Forum Moderators: coopster
I currently have a web site I'm maintaining which is consists of around 500 static HTML pages. I have been toying with the idea of coverting it to php so I can implement a CMS.
My main worry is that once I convert it over I will have to then do 500 redirects on the server so that incomming links won't be lost.
Does anyone know a way to get around this problem?
RewriteEngine On
RewriteRule ^(.*).html /$1.php [R=301,L]
That will take a request with .html at the end and make it shoot to the same page with a .php extension. The 301 means moved permanently, so search engines will recognize the .php page as the new permanent page and eventually drop all of your old links to .html pages.
Hope this helps!
If you use this:
RewriteEngine On
RewriteRule ^([^.]+)\.html /$1.php [L]
The URLs stay the same...
Then you can do some other cool stuff, like lock people out of your php:
RewriteCond %{THE_REQUEST} \.php
RewriteRule \.php$ - [F]
If the file ends in php, it cannot be opened in a browser, but Apache can still open it to serve the information =)
Justin
Edited: Adjusted to a more efficient 'forward looking' negative expression and escaped the meta .(dot) character.
AddHandler application/x-httpd-php .html If all your .html files are actually PHP ones, there is no server overhead at all, however, if only a very small number of your .html files are dynamic and the vast majority are static, then a redirect might be better.
The main problem I see happening is that the 500 static pages which currently sit on the server are going to effectivly become only a couple of pages. ie
http://www.example.com/products/cat1/prod1.html
will become:
http://www.example.com/products.php?prod=1
This is a problem because we currenly have a couple of thousand adsense words registered with google and I don't want to go into google (and overture) and change all of them. This is the reason why general redirects based on the file extension aren't going to work.
Sorry about the late response
-Harvs-
http://www.example.com/products/cat1/prod1.html
will become:
http://www.example.com/products.php?prod=1
RewriteRule prod([0-9]+)\.html$ /products.php?prod=$1 [L]
Will serve the information from products.php?prod=AnyNumber to the corresponding html URL - No file name change necessary.
Justin
BTW - Might be better to continue this in the Apache forum if this is the direction you decide to go.