Forum Moderators: phranque
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
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.
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.
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
[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