Which index (php or html) loads when both are present?

Asked

Viewed 1,217 times

3

I would like to know which index file loads in case you have an index.html and an index.php on the site.

Let’s say you’re setting up a PHP site, but you need the server for testing and so on, so I make a simple HTML page and put it there... So there were two index (one html and one php). Which would be loaded when someone entered the site?

  • As much as this is an example, if the intention is to actually test something it would be better to have a directory only for testing and out of public access, if not another server really, one for production and another for testing. ;)

2 answers

7

In the case of an APACHE server, you determine the order via the directive DirectoryIndex in his httpd.conf:

DirectoryIndex index.php index.phtml index.html index.htm

There is also the possibility to make this configuration in your vhosts individually for each domain!

This order defines which extensions the server will search for first, in the absence of one, it searches for the next one from the list.

-1


I ended up not getting the informed ways and the page always loads PHP first :... So I put a code at the top of my PHP that checks if I passed (in the url) a value 'true' for the variable 'testing' and, if YES, it loads my PHP, otherwise (if I pass nothing) it redirects to my index.html. Follow the code below for anyone else who needs something like this :P

<?php
if($_GET['testing'] != 'true'){ ?>
	<html>
		<head>
			<meta http-equiv="refresh" content="0; url=http://example.com/index.html" />
		</head>
	</html>
<?php } else {
	/* aqui o código PHP */
} ?>

That way, it loads my HTML if I enter the URL example.com, but if I get in example.com/?testing=true it carries my PHP.

Thanks for the support! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.