How do I redirect all visitors to my site, before allowing them to continue to the URL they specified?
March 20, 2009 1:33 AM   Subscribe

How to I redirect all website visitors to a particular page, before allowing them to continue to the page they originally specified (i.e. the URL they originally typed)?

I'd like this to be as low-tech as possible, although the server has PHP (I don't know PHP).

I'd better give an example:

1. Visitor A wants to visit blah.html
2. I want them to be redirected to foo.html, at the bottom of which is an autogenerated link to let them continue on to blah.html
3. Visitor A wants to visit fish.html
4. As with step 2 -- they're redirected to foo.html, at the bottom of which is a link to fish.html
posted by deeper red to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
I would think you could use an .htaccess file (assuming an apache server) to redirect all incoming traffic to a particular web page, passing the original URL in a query string, and then make the destination page PHP. Something like?

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(urls/you/dont/want/redirected|separated/by/pipes)/.*$
RewriteRule ^(.*)/$ foo.php?url=$1 [T=application/x-httpd-php]


And then in the foo.php doc you can put something like this:

<?php
echo('<a href="'.$_GET['url'].'">Click here to visit the page you wanted.</a>');
?>


This is the most basic way of doing it, and I'm not absolutely certain my htaccess stuff is absolutely correct.
posted by maxwelton at 2:19 AM on March 20, 2009


cnet's news.com does this, but without the two page part.

I haven't checked how it works, but I expect it looks for a cookie. Once you have seen the interstitial, you get a cookie and the page is reloaded. Since you now have the cooke, you see the content.
posted by devnull at 2:33 AM on March 20, 2009


I have an possible answer for this that doesn't involve editing any server config files. However, I can't seem to get pre or code tags to work any the code I'm trying to relate does not come through with the preview. What am I doing wrong? Maxwelton, how did you get it to work? Can't find anything in the FAQs or via Googlefu.
posted by Gainesvillain at 8:22 AM on March 20, 2009


I think this would work. PHP's $_SERVER variable includes a reference to the page which referred you to the page you are currently browsing. This should bounce you to foo.php if it wasn't foo.php that referred you to the page.

blah.php:

<?php
if (stripos($_SERVER['HTTP_REFERER'], "foo.php") == false) {
echo "<script type='text/javascript'> document.location = 'foo.php?url=blah.php'; </script>";
}
?>

Page content here.



fish.php:

<?php
if (stripos($_SERVER['HTTP_REFERER'], "foo.php") == false) {
echo "<script type='text/javascript'> document.location = 'foo.php?url=fish.php'; </script>";
}
?>

Page content here.



foo.php:

Page content here.

<?php
echo "<a href='${_GET['url']}'>Continue to your page.</a>";
?>

posted by Gainesvillain at 8:31 AM on March 20, 2009 [1 favorite]


I'm interested to know how you solved this issue. Were you able to find a decent work-around?
posted by Gainesvillain at 12:21 PM on March 23, 2009


« Older Who made Jamie Pressley's purple shoes, (Jimmy...   |   Where to hike in March near Fresno for Snow and... Newer »
This thread is closed to new comments.