Forum Moderators: coopster

Message Too Old, No Replies

Converting site from static HTML to PHP

what about all the sites linking to me?

         

Harvs

11:25 am on Aug 25, 2005 (gmt 0)

10+ Year Member



Hello all,

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?

lobo235

12:52 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



By making PHP handle files of the .html extension you should be able to modify your existing pages and change them into PHP scripts withoout changing their name. This will help you avoid doing the redirects but may make it more complicated to update your pages, etc.

Sarah Atkinson

4:22 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



I have a custom error page that sort of acts like a directory and informs the user that the page name has either been changed or deleted.

mattx17

4:51 pm on Aug 25, 2005 (gmt 0)

10+ Year Member



The best way would be to keep the same structure and page names, just convert the extensions. Then if you're using Apache, modify (or create) a .htaccess file in the root of your web site with this:

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!

jd01

5:24 pm on Aug 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matt has a good idea, except he is suggesting you change the URL that is displayed - yourfile.html to yourfile.php - Uh, cool URL's don't change - New URL = New Pages - Sandbox, and a plethora of other reasons to keep the URLs the same come to mind...

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.

encyclo

5:54 pm on Aug 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not do as lobo235 suggests, and rather than change the filenames or use mod_rewrite to mask or redirect, just have files with the extension .html parsed for PHP:

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.

Harvs

3:54 am on Aug 26, 2005 (gmt 0)

10+ Year Member



Thanks for the tips,

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-

jd01

7:18 am on Aug 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All the more reason to use mod_rewrite... if there is a consistency in your structure from old to new, there is no problem:

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.

Harvs

8:09 am on Aug 26, 2005 (gmt 0)

10+ Year Member



Thanks heaps everyone.

I'm going to go away and do a bit of reading on the RewriteRule, I didn't realise it was such a powerful tool.

Once again thanks
-Harvs-