.htaccess Rewrites for Magento Shops
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.

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.
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. - Read my other posts.

Hi,
I am getting 404, using apache on windows XP.
Please advice on the same for windows IIS 6
Regards
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
Thank you for sharing this Magento htaccess solution. I appreciate it! You’ve saved me hours of headache.
Hi.. Thanks for providing the .htaccess information for magento.
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?
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?
thank you perfect
thank you, your method is very good, My site has solved the problem. thank you!