View Full Version : Redirect to relative URI

05-31-2008, 12:44 AM
I want to set up dummy index files in web directories that aren't for general viewing, such as my image and script folders, that will send users to mydomain.com if they type something like mydomain.com/images in the address bar. I am thinking I will use either:
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.mydomain.com">
<?php header( 'Location: http://www.mydomain.com' ); ?>
However, I'm going to be developing the site on a local server first (I don't even have a web host yet), so I want to use a relative URI that just sends users to the top directory if they try to access any of the places I don't want them to go, so that I won't have to go through and change all these files once I'm ready to get it hosted.

I seem to remember learning something about this type of redirecting at some point, but can't seem to find anything now. :P

Thanks in advance for any help.

05-31-2008, 01:42 AM
Can’t you just send them back to their previous page using HTTP_REFERER?

05-31-2008, 01:58 AM
I don't think so. I hadn't heard of http_referrer before, but it sounds like it would only work if someone has arrived at the directory from a link. I don't intend for any links to exist that might send a person to these areas of my site, I am more interested in stopping people from looking up what is in my directories by typing the url into their address bar directly. Therefore, when they type in a directory I want to keep hidden, they will get the dummy index file which will take them to the main page of my site.

05-31-2008, 03:22 AM
why not simply

<?php header("Location: /"); ?>


05-31-2008, 06:07 AM
Thanks Adam...do you know a good reference for these types of php commands?

05-31-2008, 06:20 AM
well php.net is the best. It includes all the commands, gives exmaples, describes how they work, suggests other commands that may work better, and is fairly easy to understand(most of the time).

If you know the command you are looking for then you can use http://php.net/header or you can go to http://php.net and search for it in the search box in the upper right.


05-31-2008, 09:15 PM
Adam, thanks again.