Simple PHP redirect?

software development

#1

Hi,
I’ve been told to use this php script (below) to do a simple redirect from my main directory on the server to a subdirectory so that people can get to my main site which is setup in a sub directory, however it doesn’t do anything in firefox or internet exploder any clues what’s wrong with it?
I’ve put the code in a file named index.php in my main directory, and even chmod it to 775 just in case but no go.

It’s rather like the server is serving this up as a simple text file because I can see the code in the browser’s “view page source” which I shouldn’t be able to.

Any help appreciated.

<?php // Change to the URL you want to redirect to $URL="http://www.mydomain.com/main/"; header ("Location: $URL"); ?>

#2

You must call the file: index.php


#3

Yes, I did that.


#4

And it must be the only index.* file in the directory … do you, by chance, also have an index.html ?


#5

No, it’s the only file in my root directory.


#6

why would you put your main site in a subdirectory if you’re just going to redirect to it anyway?

your php script looks fine, provided there’s nothing (not even a blank line) before <?php. the file doesn’t need execute permissions because it’s going to be used as input to the php cgi handler – my php file permissions are mostly 644 and are working. it’s possible it won’t work for some sort of security reasons until you remove execute permissions.

if those suggestions don’t help, have a look at your log files, under ~/logs/example.com/http/ and see if there’s anything there. error.log is probably your best bet – request the web root directory and then see if there’s anything new in that file.

track7 - my dream-hosted site