Forum Moderators: phranque

Message Too Old, No Replies

.htm to php rewrite . all or?

changing pages from .htm to .php

         

old_expat

4:13 am on Feb 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm needing to change some pages from .htm and .html to .php in order to use some dynamic features.

On one of my sites I used the following in my .htaccess

RewriteRule ^([^.]+)\.htm$ $1.php [L]

I think that I remember that it rewrites both .htm and .html extensions.

What I'm wondering is, do all the file extensions in the site have to be changed, or if the server doesn't find foo.php, will it then serve foo.htm?

jdMorgan

4:54 am on Feb 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^([^.]+)\.htm$ $1.php [L]

I think that I remember that it rewrites both .htm and .html extensions.

No, that rule only rewrites .htm files.

What I'm wondering is, do all the file extensions in the site have to be changed, or if the server doesn't find foo.php, will it then serve foo.htm?

There's no magic here. If the requested file doesn't exist, then you get a 404-Not Found, unless there is some other 'agent' at work, such as another mod_rewrite rule, content negotiation, or an AcceptPathInfo setting. As this implies, what you describe *can* be done, but it doesn't happen automagically... :)

Taking a rather large step back from this problem, are you sure you need to 'rename' anything at all? You can tell your server to parse html files for PHP code if you want to...

Jim

old_expat

1:34 am on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jim,

RewriteRule ^([^.]+)\.htm$ $1.php [L]

I think that I remember that it rewrites both .htm and .html extensions.

No, that rule only rewrites .htm files.


Then addind this should handle the .html?
RewriteRule ^([^.]+)\.html$ $1.php [L]

What I'm wondering is, do all the file extensions in the site have to be changed, or if the server doesn't find foo.php, will it then serve foo.htm?

There's no magic here. If the requested file doesn't exist, then you get a 404-Not Found, unless there is some other 'agent' at work, such as another mod_rewrite rule, content negotiation, or an AcceptPathInfo setting. As this implies, what you describe *can* be done, but it doesn't happen automagically... :)

Taking a rather large step back from this problem, are you sure you need to 'rename' anything at all? You can tell your server to parse html files for PHP code if you want to...


I've heard that telling the server to parse html files for PHP code slows down the server(?) ... and my server is already a bit slow.

Renaming is not such a big deal on this site, just so I know what all I need to do before loading the pages.

Thanks,

Dave

jdMorgan

2:42 am on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Rewrite htm and html files to php
RewriteRule ^([^.]+)\.html?$ $1.php [L]

Jim