Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite for Change to PHP

.. from .htm

         

old_expat

9:31 am on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I needed to add some dynamic content to a site with about 200 pages, and that is well underway, but I assume that when I upload all those .php pages I will have about lots of 404s

I hope that someone can show me how to do a Mod Rewrite that will eliminate the 404s.

The file names haven't changed except for the .php extension.

I already have a non-www to www 301 redirect

All help is much appreciated

SebastianX

11:57 am on Jun 23, 2005 (gmt 0)

10+ Year Member



Configure your webserver to parse .htm and .html files for PHP, e.g. by adding this statement to your root's .htaccess file:

AddType application/x-httpd-php .htm .html

Now you can use PHP in all .php, .htm, and .html files. [yourdomain.com...] behaves like any other PHP script with .php extension.

old_expat

12:42 pm on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Sebastian,

My problem is I only have access to my public_html .htaccess fill .. not the root

Also, I think I was told once upon a time that the process you described puts more load on the server. Is that in error?

Span

2:54 pm on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would make the server parse your htm(l) pages for PHP. Maybe it puts more load on the server, but redirecting all your pages.. I think there's a risc in that.
But you can do it with a redirect:

RedirectMatch 301 ^/(.*)\.htm http://www.example.com/$1.php

jd01

8:15 pm on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I recommend against setting your server to parse all htm(l) requests as php, it is generally not the most efficient or effective solution.

If your files have not change, as you stated, you could either:
1. Redirect the html version to the new php version, but lose all the indexed pages while SE's pick up the new version.

2. Silently serve the php version to the html version with a simple .htaccess rule.

RewriteEngine ON
RewriteRule ^([^.]+)\.html$ /$1.php [L]

([^.]+) = Anything that is not a .(dot)
\. = Is a litteral .(dot)
html = must follow the .(dot)

/$1 = the full information stored up to the dot
.php = the new file extension
[L] = stop processing now

Please, not this is a silent redirect. IOW the browser address will not change from the .html page that is requested, but the information from the .php file will be served to it.

Hope this helps.

Justin

<RANT>

BTW I have had people who have been on shared boxes with me unambiguously turn on .htm(l) processing, and write server intensive sql scripts, with no regard for the fact that they were doing damage to everyone on the box, and at times taking my site down... It is simply in poor taste to take the 'easy' answer when you can be doing damage to others who are sharing your resources and there is another way.

These people eventually had their accounts revoked, but not until after they crashed a DB server about 5 times, and managed to take the dynamic portion of my site down (over 15K pages) for over 15 hours (total).

If you are on your own box, slow the server and write all the memory intensive scripts you like, but if not, please choose efficiency not only for yourself, but for others who also depend on the resources.

</RANT>

Added: I should state the 200 pages of this site should not create any problems, but the blanket statement for future readers, should be avoided.

old_expat

9:19 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, Gents..

In the interim, I have been told that a redirect is much faster and more efficient than a rewrite.

Basically the plan is to load the newly named PHP pages and do the redirect. Then remove the HTML pages.

Then wait 3-6 months and remove the redirect.

Opinions?

jd01

9:57 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been told that a redirect is much faster and more efficient than a rewrite.

I use a very effiecient mod_rewrite to serve the dynamic portion of my website (over 15K pages). My page load from an SQL database is an average of < 1 sec. I am not sure how much savings you will get from a redirect...

Please, keep in mind that changing just the extension of a file will cause the file to be seen as new, and file age appears to be one of the things Google looks at to determine the age of a site, so changing all the extensions on a site, may be interpreted as the same as changing every URL path on your site.

I do not see a way to keep your current URL's indexed by any search engine using a redirect, you will have to wait until the new ones are picked up, which may be very quickly to a couple of months. Any inbound links will also take time to be 'transferred' to the new files in the search engines.

The solution I posted above will keep this from happening, but if you think there are significant gains from using a redirect instead, then that is the direction you should go.

Justin

old_expat

4:52 pm on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Justin,

After an email conference we decided that redirect may be faster but it isn't worth the potential SE implications.

So we are going with the rewrite.

Thank you for your help.

jdMorgan

10:30 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's good, because
[In the interim, I have been told that] a redirect is much faster and more efficient than a rewrite.
is just flat incorrect.

A redirect involves sending a response to the client telling it to re-request the desired resource at a new URL. So, this doubles the number of requests to your server, and doubles the transmission delay seen by the user. An internal rewrite simply changes the filepath associated with a requested URL, and serves the 'new' file.

An external redirect is demonstrably less efficient than an internal rewrite.

Jim