Page 1 of 3

index.html / index.php

Posted: Wed Dec 14, 2005 3:19 pm
by mikeycorn
I have a lot of links, both internally and externally to my index.html page. I now need to add some php code to the page. Is there anyway I can get that code in there outside of having index.html immediately redirct to index.php?

Posted: Wed Dec 14, 2005 3:25 pm
by John Cartwright
You could use a meta redirection

Code: Select all

<META http-equiv="refresh" content="0" URL="index.php" />
Edit | I think I misunderstood your question.. give me a minute.

If you want to include PHP code in your index.html then you change the the AddType in your httpd.conf files to include .html files

Code: Select all

AddType application/x-httpd-php .php .phtml .php3 .php4 .php5 .html
This will allow PHP to be parsed in the file. I hope I understood this time ;)

Posted: Wed Dec 14, 2005 3:28 pm
by mikeycorn
Just to be clear, that would be the option I'm trying to avoid.

What I'd like to do is get a php include inside an .html file.

Posted: Wed Dec 14, 2005 3:29 pm
by John Cartwright
Incase you didn't notice, I edited my last post. Also, why not just have the index.php instead of both an index.html and index.php?

Posted: Wed Dec 14, 2005 3:32 pm
by mikeycorn
Sorry, I was just trying to clarify, I appreciate your taking the time to respond. :wink:

The reason I want to avoid index.php is because I have external links all over the place linking to index.html.

The httpd.conf sounds very promising, thanks.

Posted: Wed Dec 14, 2005 3:34 pm
by redmonkey
If you are using Apache and have means to adjust configuration (either directly in the httpd.conf file or via .htacess) you could use mod_rewrite to redirect requests for index.html to index.php.

Similarly, you could either add .html to the AddType declaration for the PHP handler.

Or use 'ForceType' to force the index.html file to be parsed by PHP

Posted: Wed Dec 14, 2005 3:39 pm
by mikeycorn
redmonkey wrote:If you are using Apache and have means to adjust configuration (either directly in the httpd.conf file or via .htacess) you could use mod_rewrite to redirect requests for index.html to index.php.

Similarly, you could either add .html to the AddType declaration for the PHP handler.

Or use 'ForceType' to force the index.html file to be parsed by PHP
Dude, you are making my head spin with all that, but it's good stuff.

Okay . . .

In my root folder, I see the .config folder has an ipaddr file (no extension) and nothing else. Is that where I'd create a text httpd.conf file?

Now the PHP handler, is that a different thing? I'll google it, but is there a short explanation of where to get at it?

Posted: Wed Dec 14, 2005 3:47 pm
by redmonkey
Which operating system are you working with? and do you have *full* admin/root access?

The httpd.conf will already exist, dependant on operating system it could be living anywhere, for *nix it normally lives in /etc (possibly /etc/httpd/httpd.conf) for Win systems it's normally in a 'conf' directory within the main install directory. It's probably easiest just to do a search for it.

The PHP handler is just a declaration within the httpd.conf file that tells Apache which files are to be parsed by PHP.

Posted: Wed Dec 14, 2005 3:50 pm
by mikeycorn
Maybe I need to search my webhost's FAQ for the terms you just dropped on me. At least now I know the terms to search for.

Posted: Wed Dec 14, 2005 3:56 pm
by mikeycorn
Worthless knowledgebase, searches turned up nothing.

Posted: Wed Dec 14, 2005 3:57 pm
by mikeycorn
Okay, I found this

The path to PHP on our servers is /usr/local/bin/php/

but I don't see usr from the root.

Posted: Wed Dec 14, 2005 4:01 pm
by John Cartwright
Let me put this into simple terms for you..

Look through your apache directory, if you are on a linux server you are likely to find the httpd.conf files somewhere within the /etc/ directory. For example: c:\server\apache2\etc\conf\. If you are on windows server you will find this file in the apache directory, most likely in a folder "conf". For example, c:\server\apache2\conf\. If you can't find the file simply do a search for it, simple enough ;).

Now once you locate this file, look for the AddType for php (the code I showed you in my first post) and add .html to it.

Posted: Wed Dec 14, 2005 4:02 pm
by John Cartwright
mikeycorn wrote:Okay, I found this

The path to PHP on our servers is /usr/local/bin/php/

but I don't see usr from the root.
You are looking in the /php/ directory.. go back to /bin/ and look in apache

Posted: Wed Dec 14, 2005 4:06 pm
by mikeycorn
From the / what I have is

.config

.sessions

cgi-bin

logs

Posted: Wed Dec 14, 2005 4:22 pm
by redmonkey
mikeycorn wrote:Maybe I need to search my webhost's FAQ for the terms you just dropped on me. At least now I know the terms to search for.
By the sounds of it, you are on a virtual host? if that's the case you should stop looking for httpd.conf file as if the server is setup correctly you will never find it.

If you are on a virtual host, you need to look at using .htaccess files.