Portal Home > Knowledgebase > Articles Database > How to redirect *.html to *.htm via htaccess?
How to redirect *.html to *.htm via htaccess?
Posted by robertk1, 07-22-2009, 09:52 PM |
How can I redirect html page inquiries to display htm pages? Google has the old html pages. but the new site is all htm.
I tried a 301 htaccess redirect using:
redirect 301 /*.htm /*.htm
and
redirect 301 /*.htm http://you.com/*.htm
without success. Both crash the site. Other than keying in all new page names, how do I proceed?
|
Posted by robertk1, 07-22-2009, 09:56 PM |
OK, I just found the solution, after searching for over an hour. The format is:
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.htm
Thanks to anyone who read this and was going to help out.
|
Posted by Rekhatitus, 07-23-2009, 12:26 AM |
Try this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^index\.html$ "http\:\/\/your\domain\.com\/index\.htm" [R=301,L]
|
Posted by HostSentry, 07-23-2009, 12:58 AM |
You don't need to escape the right hand side of your rule.
http://yourdomain.com/index.htm is fine
As far as the first issue of redirecting .html to .htm, just do
RewriteRule ^(.+)\.html$ $1.htm [L]
|
Posted by robertk1, 07-23-2009, 08:02 AM |
Thanks to both Rekhatitus and HostSentry, your code works better. The original I had using only one line (RedirectMatch 301 (.*)\.html$ http://www.example.com$1.htm) caused issues when no page was requested (ie http://domain.com). Your way eliminated that issue.
Last edited by robertk1; 07-23-2009 at 08:15 AM.
Reason: better description
|
Posted by HostSentry, 07-23-2009, 10:16 PM |
Your way would have worked if it was http://www.example.com/$1.htm
|
Posted by kateperry1, 07-27-2009, 08:23 AM |
Great advice - thanks for this. I have changed my site to a .co.uk domain and have had to redirect to a com - this has saved me alot of time
|
Add to Favourites Print this Article
Also Read