Forum Moderators: phranque
I like mod_rewrite but it hurts my brain...
I have searched this forum and many other sources and have even had a stab at creating my own. Yes I have also rtfm.
Please help me with a rule for sending requests for .shtml files to the same name but .html extension.
It does not sound like a hard job but has had me stumped all weekend.
Thanks in advance
Chubba
I have tried the above and no joy :o(
I have checked htaccess files being processed OK so cannot understand why this is not working...
My htaccess file looks like:
=======================
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www\.mysite\.co.uk
RewriteRule (.*) [mysite.co.uk...] [R=301,L]
RedirectMatch permanent /mypage.shtml /mypage/index.html
RewriteEngine On
RewriteRule ^(.*)\.shtml $1.html [L]
=================================
I have the RedirectMatch in there as well to fix another little problem I had, this and the first Rewrite rule work OK (redirecting [mysite.co.uk...] to [mysite.co.uk)...] so guess there is something not quite right with the rule to redirect .shtml to the same file name but with a .html extension?
Chubba
I would suggest a couple of minor adjustments, but what you have should work.
RewriteRule ^([^.]+)\.shtml$ /$1.html [L]
Jim
Thank you for replying.
I guess that has taught me more about rewrite and redirect - I had never considered a difference between a rewrite and a redirect, I had considered them the same.
/blushes
My apol's for not being more specific, just a n00b doing his n00b thang :~)
I have tried the code you kindly gave me and alas this has not worked either.
OK - the scenario is that I have a site that contains all .shtml files, for my own selfish reasons I would like them all to be .html files. I have remade the files as .html files and when users (and robots) hit a .shtml file I would like them to be *redirected* to a .html file that has the same name so that a request for mypage.shtml would be permenantly (401 header) redirected to mypage.html and likewise a request for /mydirectory/myfile.shtml would be 401'd to /mydirectory/myfile.html.
Although from what you have said my request for myfile.shtml could actually be serving myfile.html but as it is not a redirect then the address does not change in the browser? That is wild and certainly opens up another world within mod_rewrite that I had not considered...
Thanks for clearing up my confusion with redirect and rewrite - I do feel really stupid now :o( Maybe I should rtfm a bit closer.
Many Thanks
Chubba
Although from what you have said my request for myfile.shtml could actually be serving myfile.html but as it is not a redirect then the address does not change in the browser? That is wild and certainly opens up another world within mod_rewrite that I had not considered...
Yes, test it for yourself and see.
"That has not worked" is not really very useful as a status report, by the way. Please say how you tested, and what results you got. It will minimize the number of questions/answers, take less time for all involved, and result in a quicker fix for you.
To change your rule from an internal rewrite into a redirect, use:
RewriteRule ^([^.]+)\.shtml$ http://www.mysite.co.uk/$1.html [R=301,L]
That worked ;O)
OK - points taken and I will be more specific next time. Yup, understand that I could have checked the rewrite was working by changing the HTML file and requesting the SHTML file and seeing if the server served the amended page.
Thanks again as this has taught me a huge amount - apol's for not making this easier for you & me.
Chubba