Jump to content

Recommended Posts

I think his asking, if you went to a folder that has a index.php and a index.html in it and you just went to that folder (not the file) which one would load by default..

 

Well that does depend on how apache was configured, best bet is just to try it

 

if your asking is it better to have a index.php or index.html then I always create index.php as it allows me to add code without worrying about if i have a link pointing to index.html

Thanks guys,

 

I know how to configure apache to read .php or .html. My question was which one you normally use as the index.

 

It really doesn't matter one way or another. But, you will find that almost no servers are configured to read php in an .html document. You need to configure it yourself to be able to do that.

 

Doesn't mind to me, mine reads both index.html (with php inside) or index.php. So you're saying that either way is ok.

 

 

if your asking is it better to have a index.php or index.html then I always create index.php as it allows me to add code without worrying about if i have a link pointing to index.html

due to the above mentioned reason, you seem to prefer index.php, are there any disadvantages of it?

 

thanks guys.

I've started learning php and want to develop good habits right from the beginning. Hence, my elementary questions)

Remember to include something like the below in the top of the script, to prevent having the same content indexed on both the index.php file, as well as the domain it self.

 

if ($_SERVER['REQUEST_URI'] == '/index.php') {
  header('HTTP/1.1 404 Not Found');
  include_once '404.php';
  /* mysql_close($Connection); // include if you use MySQL */
  exit();
}

 

Sample 404 page:

<!DOCTYPE html>
<html lang="en">

<head>
   <title>404 Not Found</title>
   <meta name="robots" content="noindex,nofollow">
   <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
   <style type="text/css">
   </style>
</head>

<body>
  <h1>404 Not Found</h1>
  <p>Nothing was found on the specified location:</p>
  <p><?php echo htmlentities($_SERVER['REQUEST_URI']); ?></p><p><a href="/">Frontpage</a></p>
</body>
</html>

What his saying is IF you have both index.php and index.html, them a search bot may take the contents of both for indexing in search engines, the code basically tell the bot that the page its viewing doesn't exist.. but then again why have a page their at all if its only function is to not exists!

Remember to include something like the below in the top of the script, to prevent having the same content indexed on both the index.php file, as well as the domain it self.

 

Use a 301 redirect. Better for the user and better for any spider. Serving a 404 is a bad idea.

There is really no reason why you should have an index.html as start page if your site is built on php. However, like people have already told you, either way will work. Make your life easier though and just go with index.php. SEO-wise, see to that you always link to the domain itself and not to index.php (or index.html), then you will have no duplicate content problems.

<html>

<head>
<link rel="stylesheet" type="text/css" href="thisisme.css" />
</head>

<body>
<h1>Hi there!</h1>
</body>

</html>

 

You display code in index.php just as you would in index.html or any other file. The only difference is that you're able to execute php code inbetween <?php ?> blocks. You may of course also print html, css or anything else using php as well.

 

The file extension has no meaning other than which extensions you instruct the server to parse as php (or any other language). You may as well have index.google or index.tree parsed as php as well if you wish.

CSS acts on HTML. PHP outputs HTML. CSS doesn't interact with PHP whatsoever. Output your HTML, then set the CSS to act upon it.

 

Not to pick on you but of course it is possible to output CSS and every other kind of code syntax using PHP as well  :P

 

It sure is. But the CSS doesn't interact with the PHP, it is just outputted by the PHP. It acts on html, which is what I said in my original post. Not to pick on you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.