|
-
Ex-***
Read URL - PHP
Hey.
Still very much a beginner, I want to make a little php snippet that does something like this:
I might be able to do some of it, but how to I find out what URL the viewer has typed in? (This site has two aliases which are in fact the exact same site)
Thanks for any pointers!
Now listening to various rock and metal
143rd member to join Sharkyforums.
-
Hammerhead Shark
PHP Code:
$url = $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"];
BTW The Pixies are great man, I think my fav was Where is my Mind. But it's been a while too
-
Hammerhead Shark
kid A, here's an idea...
If they are on different machines or each URL directs to a different directory, forget the URL check and just do a header redirect like so:
PHP Code:
<?php header('Location: http://blablabla.mysite.com'); ?>
I have a few sites that have just the above in an index.php to redirect to a page on that URL and some redirect from one URL to another using the same exact thing, just change the value of Location in the header.
If they are in the same directory, your host could change the http server settings to do that or you could just use $HTTP_SERVER_VARS['HTTP_HOST'] (one of the variables Tekime pointed to) and do the logic on that, then run the code in the php block above.
If you have a possibility of people trying to go to a location below that, append the request URI on the site name. I once did this on a site that was linked to from a number of places with many files in different directories that needed to be redirected to the new server.
-
Ex-***
You see, I only have one webspace, with two domain names pointing to it. That means they both end up in the exact same index page, I wanted to take one of the urls and redirect the visitor to a subdomain I have, but it seems my webhost won't actually allow this..
Now listening to various rock and metal
143rd member to join Sharkyforums.
-
Hammerhead Shark
Originally posted by kid A
You see, I only have one webspace, with two domain names pointing to it. That means they both end up in the exact same index page, I wanted to take one of the urls and redirect the visitor to a subdomain I have, but it seems my webhost won't actually allow this..
Put this at the very top of the index.php page:
PHP Code:
<?php
if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'www.blablabla.com')
{
header('Location: http://blablabla.mysite.com');
}
?>
-
Ex-***
Most excellent Sir!
I thank you.
Now listening to various rock and metal
143rd member to join Sharkyforums.
-
Hammerhead Shark
No problem.
You could also do it in a single line by removing the '{' and '}' characters and putting the line inbetween them at the end of the if statement.
-
Catfish
If you're using Apache...
Why not just use the .htaccess file to redirect. It's faster. Check out this tutorial:
http://www.javascriptkit.com/howto/htaccess7.shtml
Hope it helps.
Oh yes and: Pixies. are. wonderful. River Euphrates = amazing.
Last edited by m__; 09-04-2002 at 11:16 PM.
Soyo Dragon Lite
Athlon XP 2000+ (temporary crap fan & heat sink)
512mb Mushkin PC2100
Visiontek Xtasy GeForce3 Ti200 64mb
80gig WD 7200rpm 8mb cache
Lite On 32x12x40x CDRW (black)
Lite On 16x DVD (black)
Sound Blaster Audigy Platinum (black)
Cambridge Soundworks DTT2200 5.1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|