htaccess not allowing to save data in Magento Backend - .htaccess

I want to remove index.php from all admin URLs in Magento. I have written the following code in my .htaccess file.
Magento is installed in a subdomain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/$1
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteRule ^(/)?$ test/ [L]
RewriteBase /test/
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php
RewriteCond %{REQUEST_URI} ^(.*)index.php/admin.*$
RewriteRule ^index.php/admin(.*) /admin$1 [L,R]
By this code I have found success in my requirement, but now I am unable to save data. Please help me if any one has idea about this.
Any help will be appreciable.

If your all settings are correct and you are making the changes on Live server, then you need to wait at least one day as the
Live Server takes some time to change the htaccess configuration setting. ;)

Related

Htaccess rewrite / redirect issue from .png.webp back to png

Can any experts in .htaccess tell me why this isn't working? (it's the last line that is key - the .png.webp to png rewrite) Please help!
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www.test.com [NC]
RewriteRule ^(.*)$ https://test.com/$1 [L,R=301]
RewriteRule ^(.*)\.webp.png$ $1.png [L,R=301]
Example issue:
https://centiqsap.com/wp-content/uploads-webpc/uploads/2020/07/Group-13-min-2.png.webp
Needs to rewrite and redirect to
https://centiqsap.com/wp-content/uploads-webpc/uploads/2020/07/Group-13-min-2.png
Have your htaccess file like this way once(I have added new rule and kept OP's old rules too in rules file). Please make sure you clear your cache before testing your URLs. I have also fixed some minor issues, like your https redirection rule should be at very first and you should exacpe .(dots) in regex too.
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.test\.com [NC]
RewriteRule ^(.*)$ https://test\.com/$1 [NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(.*\.png)\.webp/?$ $1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.webp -f
RewriteRule ^(.*)/?$ $1.webp [NC,L]

Drop the .html from URL in .htaccess

I am having a hard time trying to drop the .html for our newly updated website through .htaccess. I have tried a number of different lines of code copy and pasted from the internet, but I'm sure it's something simple that I just don't have the experience to see!
In short, I want to make this request (which is a 404) drop the .html:
http://mysite/cmt-grooving-sblade.html
To this:
http://mysite/cmt-grooving-sblade
Any help you could give will be I will be very grateful for!
So far, my .htaccess looks like this. The first section was already there, the rest is my recent attempt.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can use this to remove .html from your URLs:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
It will leave you with your desired URL: http://mysite/cmt-grooving-sblade. Make sure you clear your cache before testing this.
Try this;
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

htaccess redirect from subdirectory to subdirectory

I'm trying to set up a local instance of a php site working in a server, in the "/" directory. My local instance will work in my development environment in a "/subdirectory/".
I'm trying to translate .htaccess to adapt to this, but I always get a 404. This is original .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
And these are my tries:
RewriteEngine on
RewriteBase /mylocaldirectory/
# Not in local! RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Not in local! RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
Also
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)my-nice-url$ /index.php?p=ugly_url
Thank you
If i got you right, you want make a user friendly url, i do it like this:
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=$2 [L]
or
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=what-ever-you-need [L]
Hope it help you.

htaccess is not ignoring images like it should?

I have an htaccess file that is supposed to be redirecting any non-existing files/folders/etc into the application's index.php script where they are handled by the application's SEO rewriting.
The problem is that any missing images are also redirecting into the application which is causing a lot of additional load and is unnecessary. I've been attempting to get this htaccess file to ignore images, but even though this should be working, it's not, and I'm completely out of ideas as to why...
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !.*\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?sef_rewrite=1 [L]
When I make a request to http://www.domain.com/folder_that_doesnt_exist/image.jpg this redirects to index.php
When I make a request to http://www.domain.com/folder_that_does_exist/image.jpg it also redirects to the index script
I'm not sure what I'm missing here because unless OR is specified, shouldn't the RewriteRule only be applied if the request passes all of the RewriteCond statements? which it clearly should not be passing...
Update:
I've modified the code to the following just to eliminate possible issues, but it still redirects all non-existing images into the script...
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?sef_rewrite=1 [L]
Maby try this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} \.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteRule .* - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

404 page not found in YAMS

I would like some help here. I am using MODx with YAMS module which is for multilingual. I follow the installation and setup document from YAMS but I still get 404 page not found.
I would like to get:
localhost/sub/en/index.php?id=1
localhost/sub/fr/index.php?id=1
localhost/sub/th/index.php?id=1
the original link is
localhost/sub/index.php?id=1
here is rewrite rule in htaccess file. I got the rewrite rule from YAMS in "Server Config" tab.
# Friendly URLs
RewriteEngine On
RewriteBase /sub/
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# Redirect from mydomain.com/rootname to mydomain.com/rootname/
RewriteRule ^en$ en/ [R=301,L]
RewriteRule ^fr$ fr/ [R=301,L]
RewriteRule ^th$ th/ [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^th/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I am trying to search all the solutions everywhere. still no luck. please suggest or point me what i do wrong?
Thanks in advance
If you are getting links like localhost/en/index.php?id=1 in the frontend You have to fill the "MODx Subdirectory" field with "sub". You will find it in Modules->Yams->Other Params
Actually the problem is .htaccess file. I copys all .htaccess from YAMS and replaces the whole original .htaccess file. To solve my problem, I copy only friendly URL part and replace only this part in original .htaccess file.
here what I copy from YAMS and replace in my .htaccess file:
# Redirect from mydomain.com/rootname to mydomain.com/rootname/
RewriteRule ^en$ en/ [R=301,L]
RewriteRule ^fr$ fr/ [R=301,L]
RewriteRule ^th$ th/ [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^th/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Many thanks for suggestions.

Resources