Magento .htaccess SEO redirects

This is where I intend to list important .htaccess tweaks for Magento.

This codes redirects the index.php version of the homepage to the non index.php without messing up the backend access.

RewriteEngine on
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{THE_REQUEST} !admin [NC]
RewriteRule ^index\.php(.*)$ http://www.YOURSITE.com$1 [L,R=301]

You should also redirect the name of the homepage in your CMS pages to the main version

redirect 301        /home  http://www.YOURSITE.com/

This code removes the trailing slash for Magento URL to the non trailing slash version of the page.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]

These increase the SEO value of your website by reducing the number pages search engines see thereby increasing the SEO on the on the 1 you are allowing them to see.

4 comments
  1. Hi dan

    @ trailing slash removal:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
    RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]

    What is the correct version for a site completely on https?

    just: RewriteRule ^(.+[^/])/$ https://%{HTTP_HOST}/$1 [R=301,L]?

    thanks
    dan

    1. hi dan
      magento 1.9.1.1, all urls on https

      with this part:
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
      RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
      the swatches do not work anymore. any idey?
      dan

      1. this seems to work:

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !(.*)/$
        RewriteCond %{REQUEST_URI} !(.*)\.(html|shtml|php)$
        RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]

        dan

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to remove the Estimate Shipping & Tax Block area in Magento shopping cart

Next Post

Magento Log Cleaning

Related Posts