index.html / index.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

index.html / index.php

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 ;)
Last edited by John Cartwright on Wed Dec 14, 2005 3:28 pm, edited 1 time in total.
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post 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?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post 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.
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post by mikeycorn »

Worthless knowledgebase, searches turned up nothing.
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
mikeycorn
Forum Newbie
Posts: 23
Joined: Thu Jun 23, 2005 9:27 pm

Post by mikeycorn »

From the / what I have is

.config

.sessions

cgi-bin

logs
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
Post Reply