Design Directory Discussion Forum Design Job Board Add Your Site Post a Message Post a Job / Gig

HomeDevelopers → Re: Switching HTML to PHP

Hi,

I'm switching .html files to php on scene360, this to add some includes to simplify updating. We have a big collection of articles that have been linked on the Internet...by changing the file extension it is going to create a lot of "page not found" a slight problem. Is there some script to forward html to php, so that it automatically redirects to the right page?

This may be a far fetched q, but I thought I'd ask.

Thanks.
Visit My Website | -Adriana www.breathewords.com www.scene360.com
Hi Adriana,

If you create a .htaccess file in your root folder of your website, with the following contents:


RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteRule ^(.*)\.html$ $1.php [R=301,L]


Then all .html files will point to their .php equivalent; simple rename all of your .html files to .php and the 301 (Permanent Redirect) will deal with that.

Gav
Hi Gavin,

Thanks for the very helpful tip.
Visit My Website | -Adriana www.breathewords.com www.scene360.com
Gav's suggestion is the best thing for a quick and easy solution in PHP.

However, it does prove a valuable point that using a full file-structure with default names could be a good move...

so if you had this:

/products/prod1.htm
/products/prod2.htm
/products/prod3.htm

It would be better to use additional directories like this:

/products/prod1/index.htm
/products/prod2/index.htm
/products/prod3/index.htm

Doing so would allow you to link without "index.htm", and then switching from .htm to anything else would be much less of an issue.

Then, of course, with any server-side technology, you could consider URL Rewriting as a very plausible solution.

http://en.wikipedia.org/wiki/Rewrite_engine
Visit My Website | ---- ---
You should read a bit into REST.

http://www.xfront.com/REST-Web-Services.html

The URLs are more memorable, it is search engine friendly and as a developer it is easier to find the resource you wish to edit.
Not sure how your site is setup now Adriana, but here is the rewrite rule i'm using quite a bit at the moment for friendly php urls.

RewriteEngine on
RewriteRule ^product/([A-Za-z0-9-]+)$ /product/$1/ [R]
RewriteRule ^product/([A-Za-z0-9-]+)/$ /index.php?itemID=$1

First line makes sure there is always a trailing slash on the url. The second rewrites the item ID (say kitties) in the query string to be a directory name, preceded by a category name. So it ends up being: yoursite/products/kitties/
Hi Paul,

I've been using Gavin's script on HTaccess file. It has worked great. I did have some hiccups with the server change, some files weren't working with the header DOC part...but I corrected some page manually. For now it is okay.

Thanks.