-
redirect code/software
Hi, guys
I have checked out some redirect code on various platforms (perl, php, and js) but is doesn't seem to work like I want. I was looking for code that would redirect from a page that no longer exist to a page that does.
eg. someone got to a page from a search engine like main.html, and now the page is main.php. how do I make it so it looks at the url and redirects it to the right one.
I even looked into the htaccess file but I am not too familiar on how to do it.
so if anybody has any idea, please let me know.
TIA
-
I suppose you could keep the main.html page and have it redirect to main.php.
-
Ya I thought about that way but I was trying to cut down on how many files were on the server. I might have to use that as a last resort.
-
hmm... is one a html and the other php? because if they were both html or both php, you could create a link with the :
'ln -s' command.
-
yes, the old one is html and the new one is php. explain what you mean by 'ln -s' command, never heard of it.
-
thats the unix link command. if you using windows, it's like a shortcut, you can have index.html point to list.html so whenever someone visits your directory they get list.html.
but you can't change extensions, because the parser won't do it right unless it's configured to parse everyting in a certain directoy.
i think the only option you have is a redirecter script in the file, unless you can configure your server to respond with a 3xx error code to tell the browser the object has moved.
-
thanks for that useful information.
now do you know of any redirecter scripts that I could put in the file that would read the url? I am using a error script that detects when a file is gone/don't work anymore that someone tried to run, I thought that 404 was the correct error for a file that is moved/not found, if not I guess I'm stuck using the old html file with a meta redirect.
-
If you could replace the original 404 file with your own file(php), you could somehow check if the not found URL is index.html and if so, then redirect to index.php.
-
that is what I would like to know dennis, how.
I have my own 404 page. do you know how to check url to see if it is index.html??
-
Well, you can try using $HTTP_SELF but I'm not sure if that would get the URL of the 404 page, or the page that caused the 404.
-
I think that would get the page of the 404, not the one that caused it
-
What about $HTTP_REFERRER? (not sure if that's spelt correctly)
-
well theoretically that should work. have to try it out.
-
Hey dennis, the correct function to use was
PHP Code:
$location=getenv("REDIRECT_URL");
thanks for leading me to the right place though. :D
that function gave me the text after the domain name.