Forum Moderators: coopster

Message Too Old, No Replies

Switching from HTML to PHP

         

Lpe04

9:54 pm on Jun 22, 2004 (gmt 0)

10+ Year Member



I would like to switch one of my sites to PHP because I like it a lot better than HTML and find it a lot easier and more versatile to use. The only problem is my website has already been indexed for all the HTML pages. Should I try to switch over to PHP, or would it hurt my site in the search engines too much?

What would be the easiest and best way to switch to the .php extensions for the search engines? Should I leave the original .html files there and just put the .php pages on the site map to get indexed (although I am afraid this will be considered duplicate content), or should I use redirects and just suffer a search engine ranking drop on my pages? Or is there any way to keep the rankings? Any help is greatly appreciated.

Thanks

Timotheos

10:06 pm on Jun 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can get your html files parsed for php. See the following thread.

[webmasterworld.com...]

olwen

10:14 pm on Jun 22, 2004 (gmt 0)

10+ Year Member



Assuming you are on apache add these lines to .htaccess
AddHandler php-script .php .htm .html
AddType text/html .php .htm .html

This will treat all .htm or .html files as PHP

WhosAWhata

4:37 am on Jun 23, 2004 (gmt 0)

10+ Year Member



that is the best way to go, but an alternative would be to change to php extentions with the same filenames then redirect with .htaccess

yowza

6:43 am on Jun 23, 2004 (gmt 0)

10+ Year Member



Unless you are going to make use of the PHP with dynamic content, why change it? The comment that you like PHP better than HTML makes it sound like you think they are similar. They are completely different (in case you didn't know). There is no need to change unless you have a legitimate use for a Server side scripting language.

Lpe04

7:31 am on Jun 23, 2004 (gmt 0)

10+ Year Member



Thanks for the replies guys. I find php better because I like to use server side includes, which allows me to easily update content on my site by just changing one page, unlike HTML which requires a lot of work in updating by having to update each page individually.

"Assuming you are on apache add these lines to .htaccess
AddHandler php-script .php .htm .html
AddType text/html .php .htm .html
This will treat all .htm or .html files as PHP"

So I can use PHP server side includes and it will work with an HTML page? If so this would work great, although I will have to get my host to change the .htaccess for me, as I don't have access to it as for as I know.

As far as redirects, I'm guessing I will lose some search engine rankings for awhile, but I may do this to benefit more in the long run.

HelenDev

11:09 am on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can normally use server side includes without switching to php. You just need to configure your server for this.

Lpe04

5:40 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



Would it still be the same code for the server side includes in HTML? For instance, right now I am using <?php require("test4.html");?> or is there a different code to use? Sorry if this is a basic question, I am new to this. Thanks.

ogletree

5:46 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just put this line in your .htaccess file

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

Now when I put <?php include("top.txt");?> it works fine on index.html

StupidScript

5:48 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If SSI (server side includes) are enabled in your web server configuration files:

<!--#include "somefile.html"-->

will do the same thing as:

<?php include "somefile.html"?>

does on a PHP-enabled server.

Many commercial hosts do not enable SSI when your hosting account is one-of-many on a machine, as it slightly increases the load put on the server as it compiles the page for delivery. Ask your provider.

Also, you may not see your .htaccess file in your FTP program because the prepended dot causes it to be hidden. Often, if it exists, you can specify that it is the name of the files you wish to transfer, and even if you can't see it, it usually works. Likewise, you may be able to telnet/SSH into the server and find/modify the .htaccess file, which will not be hidden in that environment.

ogletree

5:50 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



olwen what is that first line for. I only have the second line and have never had any problems.

StupidScript

6:10 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ogletree: You are using different syntax that accomplishes the same thing (approximately) as the other suggestion:
1) AddType application/x-httpd-php .htm .html
Registers .htm & .html files as PHP application files, which includes both text rendering and executable scripts.

2) AddHandler php-script .htm .html
Registers the executable scripts.

3) AddType text/html .htm .html
Registers text rendering.

(2) and (3) together approximate (1).

StupidScript

6:17 pm on Jun 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually...(3) is pretty default, and is likely unneccessary. Use (1), alone for the best result.

BTW: Any type of server side parsing and compilation, like SSI or PHP, will cause the server to take a hit. It's not too bad unless you have a lot of traffic.

Adding the line to your .htaccess file limits the files parsed to files in that directory.

Adding the line to the server configuration file and restarting the server applies the instruction to every file on your web server with those extensions. This means that every .htm and .html file will be parsed and compiled by PHP before delivery, regardless of whether or not you used PHP in those files.