On a Magento based ecommerce site I am trying to remove index.php from URLs as well as 301 redirect non-www to www.
Default URL: http://www.example.com/index.php/super-cool-product.html
Desired Product URL: http://www.example.com/super-cool-product.html
Also 301 redirecting non-www to www:
example.com/super-cool-product.html
to:
http://www.example.com/super-cool-product.html
As well as:
http://www.example.com/index.html
to:
http://www.example.com
This is what I currently have:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.rejuvahealth.com/$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.rejuvahealth.com/$1 [R=301,NC,L]
To 301 redirect index.html:
If you configure your Base URLs correctly, Magento should automatically redirect to the www. version.
For index.php rewrites, go to Configuration > Web > Use Web Server Rewrites and change to ‘Yes’.
Now open your htaccess and change this line:
to this:
Assuming that your Magento folder is on the root. Be careful when using web rewrites though and ensure you back up before making any changes.