Forum Moderators: coopster

Message Too Old, No Replies

Changing homepage from .html to .php

How do I change my homepage from .html to .php

         

riospace

2:47 am on Oct 11, 2006 (gmt 0)

10+ Year Member



I want to change my homepage from .html to .php so that the page will by dynamic. What do I need to do to make this change properly. I am new to php and do not want to throw my site into chaos. I also do not want to cause problems with search engines.

If I get ride of the index.html page and replace it with index.php page and then change all of my internal links to point to the new page will everything work properly?

eelixduppy

2:55 am on Oct 11, 2006 (gmt 0)



Assuming you are running Apache, you first want to go into your httpd.conf file to change the following setting:

DirectoryIndex index.html index.php

This will use either index.html or index.php as the directory index. If you are going to change your homepage to index.php, it will then be the directory index. This may be already implemented if you are using a hosting company.

>>>will everything work properly

It should :)

Good luck!

riospace

4:16 am on Oct 11, 2006 (gmt 0)

10+ Year Member



>>>DirectoryIndex index.html index.php

I set the Directory Index and I am ready to go.

Just one last thing, should I have all my internal links point to site/index.php or just site/

I have read different opinions about linking to the actual file. I just want to know which way is the best for seo, etc.

Also, should I use some kind of redirect for sites that link to my index.html page. My index.html page has been active for 4 years so I assume there are a number of sites etc. that link to the www.example.com/index.html

If I should use a redirect which one would be the most search engine friendly? Will changing from index.html to index.php with a redirect cause any search engine problems?

barns101

11:07 am on Oct 11, 2006 (gmt 0)

10+ Year Member



Use a 301 redirect from index.html to index.php and then all internal links should point to "site/" (no filename).

riospace

7:09 am on Oct 12, 2006 (gmt 0)

10+ Year Member



I changed my homepage to .php and I set up the 301 redirect as follows:

redirect 301 /index.html http://www.example.com/index.php

I also directed all of my old internal links to ../index.html to /

Now no matter if you type in site.com or click on an internal link / the address goes to site.com/index.php never simply site.com. Will this cause any search engine problems? If I take the redirect out then it will serve the php page without the index.php. Does this matter and why do my external and internal links only go to site.com/index.php and not simply site.com when I have 301 redirect active even if I am not typing in the old index.html extension?

[edited by: jatar_k at 5:58 pm (utc) on Oct. 12, 2006]
[edit reason] examplified [/edit]

barns101

12:14 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



Is the index.html file still in your webspace? If it is still there, your web server is probably set up to serve index.html before index.php if no file is specified (i.e. you go to www.site.com/) and so the visitor will trigger the 301 redirect because index.html is served by default. If you delete index.html the server should automatically serve index.php without triggering the redirect (I think).

riospace

8:11 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



I deleted the index.html file from my server, but when I type example.com it is still redirecting to example.com/index.php. Why is it still redirecting when the index.html file does not exist. If I remove the 301 redirect then the example.com goes directly to the php page without forwarding. Why is this happening?

benevolent001

8:17 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope you wont mind asking? why are you going for this change? just changing pages to php because you want dynamic pages extension only doesnt make real sense , sorry it may be foolish question , but i just asked it.

Are you adding some real dynamic php code over there? or just renaming .html to .php and changing links accordingly

riospace

9:10 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



I am not sure that I am going about this the right way, but I only want two pages on my site to be dynamic. My homepage and my news page. I was using:

I was using the following code in .htaccess to execute .html pages as PHP:

AddType application/x-httpd-php htm html

I was told and read in forums that this was a waste of resources since my site is almost entirely static html pages because the code above will have the server scan everypage being accessed for php content.

I am not sure if changing the homepage to .php file is a good idea but I am giving it a try.

bluesmandeluxe

9:32 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



What benevolent001 said.

Do you have any php scripted code on your homepage that performs a "dynamic" function?

In other words, did you add code to your html that starts with "<?php" then has specific code that performs dynamic functions and ends with "?>" - it would look similar to this stuck in the middle of your regular html:

"<?php
$id = $HTTP_GET_VARS[id];
//find file someguy
$someguy_query = "Select someguy from somefile where (someguy_id = '$id')";
$someguy_result = mysql_query("$someguy_query") or die(mysql_error());
$myrow = mysql_fetch_array($someguy_result);
?>"

If not ... then it is not a php "dynamic" page. It is still just a static html page and using the php extension is pointless.

riospace

9:57 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



Yes, I have three php codes in my homepage.

barns101

12:59 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



It sounds like your server is set up to serve index.html before index.php (which is normal). However, the redirect to index.php is kicking in even though index.html doesn't exist.

I would suggest using .htaccess to change the directory listing order so that when someone tries to access site/ they are served index.php by default. Leave the current 301 redirect in place so that SEs and anyone following old links will still get taken to the new page.

Use this code in your .htaccess file:

DirectoryIndex index.php index.html

This means that if index.php is present, it will be served first, and then index.html is served if index.php is not present.

bluesmandeluxe

1:25 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



And you can also make index.html auto redirect as well (not instead):

Replace your index.html with this:

"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>redirect</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="0;URL=http://www.somesite.com/index.php">
</head>

<body>

You are being redirected to our new home page. If you do not get there automatically in 5 seconds, <a href="http://somesite.com/index.php>click here</a>
</body>
</html>"

barns101

2:55 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



I read that SEs frown upon Meta redirects? Could anyone clarify this?

bluesmandeluxe

6:47 pm on Oct 13, 2006 (gmt 0)

10+ Year Member



This is known as a "temporary" redirect. It is not a good idea to keep it for a long time (more than a few months) in the totally off chance that a SE will decide to get strict on your butt (they generally only do when you have a lot of potential spamming violations on your site/pages).

But if you also have permenant redirects in place on your server, than the bot should be smart enough to realize that the temp is a backup to the perm.

Anyone, please correct me if I am wrong.

Dave