Call our sales line
08000 484 679
Home > E-Commerce SEO, Magento, Magento Tutorials > .htaccess Rewrites for Magento Shops

.htaccess Rewrites for Magento Shops

Posted on: 7th Oct 2009 By: Adam Moss 8 Comments

Magento shops have an annoying way of adding /index.php to every URL which has a negative effect on the search engine optimisation as there’s no way of specifying your canonical URL. The default setup doesn’t enable you to have your own mod_rewrites so there’s several steps you have to take:

 1. Enable URL Rewrites in Admin
Go to System > Configuration > Web > Search Engines Optimization and switch ‘Use Web Server Rewrites’ to Yes.

URL Rewrites

2. Modify the root .htaccess
Youcan get to your .htaccess file easily by FTP, or if not you can use a file manager on your hosting account which is what I did using Plesk’s file manager. Once you have it open to edit, you’ll see it’s a long file with a lot of commented text. First, you need to look for the section that looks like this:

 ############################################
## you can put here your magento root folder
## path relative to web root

#RewriteBase /magento/

Un-comment it and change it to:

    RewriteBase /

This will rewite everything to your root directory instead of a Magento directory. As it was originally commented out, it didn’t have any effect.

3. Add Rewrite Code
Finally you need to find the part a bit further down that’s written like this:

############################################
## rewrite everything else to index.php

RewriteRule .* index.php [L]

</IfModule>

Underneath the part which says RewriteRule.*index.php[L] add the following lines of code:

    RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.co.uk/$1 [R=301,L]

RewriteCond %{http_host} ^yourdomain.co.uk [NC]
RewriteRule ^(.*)$ http://www.yourdomain.co.uk/$1 [R=301,NC]

Where ‘yourdomain’ is your domain’s name. That will now remove index.php from the end of the address, as well as turn all non www URLs into www. URLS.

By Adam Moss

Adam is Ecommerce Manager and a PHP developer at Creare Group. Adam is responsible for training Magento development within the company. Follow Adam on Twitter: http://twitter.com/adampmoss. - .

8 Responses to “ .htaccess Rewrites for Magento Shops ”

  1. Vijay Vishwakarma
    #1 | 12th July 2010

    Hi,

    I am getting 404, using apache on windows XP.

    Please advice on the same for windows IIS 6

    Regards

  2. Nilesh
    #2 | 7th April 2011

    Hello
    i used it,it is working on my local linux Server but when i am upload this code on my live Server then it gives me 404 Page Error.
    Can you Please help us .

    Thnaks in Advance
    Nilesh Gosai

  3. Dustin B.
    #3 | 25th April 2011

    Thank you for sharing this Magento htaccess solution. I appreciate it! You’ve saved me hours of headache.

  4. Ravi Kumar Datti
    #4 | 20th June 2011

    Hi.. Thanks for providing the .htaccess information for magento.

  5. Matt
    #5 | 5th August 2011

    This worked for me for the simple URL /index.php however didn’t work for the hundreds of other duplicate pages created like /index.php/other-page. Is there any chance of adjusting the code to make the effect broader?

  6. Matt
    #6 | 5th August 2011

    This worked for /index.php but not for the numerous pages formatted like /index.php/other-page

    Any chance you can adjust the code to get a broader scope?

  7. serdar
    #7 | 16th October 2011

    thank you perfect :)

  8. Paul
    #8 | 30th July 2012

    thank you, your method is very good, My site has solved the problem. thank you!

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Follow us on Twitter

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.