1. Home
  2. Prices
  3. Guided Tour
  4. New Shop
  5. Shop Review
  6. Ecommerce Marketing
  7. Ecommerce TV
  8. Magento Developers
  9. Portfolio
  10. Blog
  11. Contact
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 Leave a comment 1 Comment

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.

  • Twitter
  • AIM
  • WordPress
  • LinkedIn
  • Facebook
  • StumbleUpon
  • Technorati Favorites
  • Delicious
  • Ping
  • Digg
  • Bebo
  • Reddit
  • MySpace
  • NewsVine
  • Google Bookmarks
  • Sphinn
  • Propeller

One Response to “.htaccess Rewrites for Magento Shops”

  1. Vijay Vishwakarma

    Hi,

    I am getting 404, using apache on windows XP.

    Please advice on the same for windows IIS 6

    Regards

Post A Comment