Forum Moderators: bakedjake

Message Too Old, No Replies

mod rewrite globally redirect htm to shtml and show new URL

how to use mod_rewrite to redirect all extensions

         

Egbert Souse

9:02 pm on Jul 6, 2003 (gmt 0)

10+ Year Member



Hello,

I'm new here I looked thru all the mod rewrite posts and did not see the answer to my question. So if it was already answered, please forgive me and point me to the right page.

I have recently updated our site. I was using FrontPage and got rid of it. I changed most of the pages from .htm extension to .shtml

I have a global redirect set up in the .htaccess file, it is working almost correctly. The redirect is happening, but the new page still displays the .htm extension. those .htm pages are not existing where I am testing this. I want it to display the correct shtml extension. I do not want to do page by page as thee are over 90 pages.

i.e. stevia.htm [old extension that no longer resides on the server] is still displayed as stevia.htm even though the actual page is stevia.shtml

Below are the rewrite instructions I am using in the
.htaccess file. Your help is greatly appreciated.

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1 [C,E=WasHTM:yes]
RewriteCond %{REQUEST_FILENAME}.shtml -f
RewriteRule ^(.*)$ $1.shtml [S=1]
RewriteCond %{ENV:WasHTM} ^yes$
RewriteRule ^(.*)$ $1.htm

For the record, this is a real basic change from the code at
[engelschall.com...]
from the section entitled "Backward Compatibility for YYYY to XXXX migration"

Thanks in advance for your help.

jdMorgan

11:25 pm on Jul 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Egbert,

Welcome to WebmasterWorld [webmasterworld.com]!

You'll need to use an external redirect. Try changing the last Rule to:


RewriteRule ^(.*)$ http://www.yourdomain.com/$1.htm [R=301,L]

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

Egbert Souse

8:17 pm on Jul 7, 2003 (gmt 0)

10+ Year Member



Hey Jim,

Thank you for your good wishes and for your really fast post.

I tried your solution but I still end up with a .htm extension rather than a .shtml extension. Any ideas?

Also, I don't understand what the L is for

RewriteRule ^(.*)$ [yourdomain.com...] [R=301,L]

Can you please explain. Thanks.