Jump to content

Redirect Script on index.php Not Working 100%


Recommended Posts

I don't know if I did this incorrectly from the start, but this is my situation:

 

I have multiple domains pointing to the same server space.  I have a php script in the index.php of the root that figures what domain was typed, then serves up the proper page.

 

For instance, here is a sample of my script, edited to not give away too much information:

 

<?php
//$host = $GLOBALS['HTTP_HOST'];
$host = $_SERVER['HTTP_HOST'];

$site1 = "site1";
$site2 = "site2";
$site3 = "site3";
$site4 = "site4";

//if site1
if(stristr($host, $site1)){
header('Location: http://www.site1.com/site-one-index.php');
}

//if site2
elseif(stristr($host, $site2)){
header('Location: http://www.site2.com/site2/index.php');
}

//if site3
elseif(stristr($host, $site3)){
header('Location: http://www.site3.com/site-3/');
}

//if site4
elseif(stristr($host, $site4)){
header('Location: http://www.site4.com/site4/file/index.php');
}

else {
include "script/config.php";
include "script/detect.php";

if ($page_name=='') {
include $browser_t.'/index.php';
}
elseif ($page_name=='index.php') {
include $browser_t.'/index.php';
}
else
{
include 'errors/404.php';
}
};
?>

Now, this works great if somebody types in the address properly.  Even if somebody types in the wrong address, it will direct somebody to a nice 404 page.

 

The problem is if somebody types in a page that doesn't exist, and ends it with "/".

 

For instance, www.SITE.com, works like it should.

www.SITE.com/page.php works like it should.

www.SITE.com/folder works like it should (serving up an error page).

www.SITE.com/folder/ works like it should if I have an actual index.php file in that file (serving up the index.php page)

www.SITE.com/nonexistantfolder/ does not work properly.  It serves up a fake index.php file, not directing to the 404 page.

www.SITE.com/nonexistantfolder/index.php does not work properly. It serves up a fake index.php file even though it's not physically on my server.

Google thinks my site is hacked because apparently there are hundreds of SITE.com/nonexistantfolder/ pages serving the exact same index.php file, when instead there should be a redirect to a 404 page.

 

I've been thinking for months how to fix this. I cannot wrap my head around it.  I need to somehow take every "/" or "/index.php" and check my actual server space for a physical copy of an index.php file and return that, or send them to a 404.php page.

 

I just can't figure this one out.

Link to comment
Share on other sites

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.