Properly Removing the .html Extension from URL’s & Handling the 301 Redirects in Magento
By default, Magento uses the .html extension in all catalog based URL’s and quite often a site may launch using this default URL format. Most Magento store owners will be aware that from the Magento admin, you can easily remove the default .html extension from the URL’s (like the screenshot below) but once a store has already gone live and there are already thousands of the .html URL’s indexed in search engines or many backlinks pointing the .html URL’s, you should implement a global 301 redirect to handle the redirecting of all URL’s containing a .html extension to the counterpart without.
You can access the above with your Magento admin at System > Configuration >CATALOG > Catalog > Search Engine Optimizations and then the Product URL Suffix and Category URL Suffix will contain the .html extension that you can remove.
By removing the .html suffix, you can modify URL’s from the likes of:-
http://www.example.com/category/product.html
To the more friendlier / cleaner counterpart:-
http://www.example.com/category/product
So immediately after removing the .html extension suffix from the fields in the above screenshot, you must immediately ensure that all URL’s with .html 301 redirect to the version without by implementing a rule in your Magento root .htaccess like so:-
Find RewriteBase / in your .htaccess file and add the following directly below it:-
############################################ ## Removes .html suffix from URL's and 301's to those without RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP RewriteRule (.*)\.html$ $1 [R=301]
This rule may require to be implemented in different ways from store to store depending on the setup and any other rewrites it may have in place.
Hi there
Picking your brains after going around in circles in the hope you may be able to give another pointer 😉
We have remove .html from product suffix, reindexed and recached.
As this didn’t work we assumed it must be something to do with an incorrectly configured htaccess file so reinstalled default magento htaccess and then added the piece of code above.
Still nothing…
Disabled plugins which we know affect URL structure (manadev and creare); still nothing….
Any ideas you may have as to the cause would be greatly heard 🙂
Hey Vicki, thanks for leaving a comment.
So just to clarify then, after all of the above, all your URL’s still contain .html at the end of them?
One thing that might be worth trying is toggling your store scope in the system configuration to ensure that .html isn’t added as a suffix for your actual store website/store view in addition to default config.
Hey, nice post.
I am using Magento 1.9 and have removed the url suffix for both products and categories. Magento is handling the redirects just fine, but i havent added the htaccess bit you mention
Is it really necessary, if i dont get 404s?
Was there an update of magento between your post and now that changed the way this works?
Any insights would be appreciated.
Yes, you’re right Rob, since this post was originally written, something has been released with the Mage core that auto-redirects the category and product URLs is the suffix is removed/added therefore not requiring the change to .htaccess.