Skip

this webpage is for loading and unloading only. no bookmarking
April 25, 2009 7:26 AM   Subscribe

Is there anyway with apache redirect's (mod_rewrite with a 301 rule) for the underlying web page to detect the redirect and run some JS or PHP (or anything really) to say, 'HEY USER!!! Ya you! Change your bookmarks please!'?

I would like to change the domain name for a website I have and I can handle the actual rewrite rules just fine, but I would really like people to notice when they have been redirected so I can eventually phase out the old domain name.

Ideally, this could be bit of inline text above the banner for the web page. (Maybe I could make it blood red or blinking if I was feeling evil....)

I do *not* want to use pop-ups. Not web page pop-ups nor notification pop-ups. (You know, those 'OK or Cancel' ones). That would be annoying.

PS - I am aware that changing the domain name will kill page rank, etc. It is a very low traffic site and I am not concerned about that at all.

And now that I logically follow that through... It being low traffic, I guess this is a slightly moot question, but now that I am stumped it is going to bug me until I find an answer.
posted by cayla to Computers & Internet (8 answers total)
 
Couldn't you just rewrite the old url to something like http://newurl.com/index.php?redirected=true ?
It would be trivial then to add a line of scripting to the page to check for that GET parameter and output an additional message..
posted by Nightwind at 7:45 AM on April 25, 2009 [2 favorites]


I believe this technique will accomplish what you want. It will pause on your old domain for 10 seconds and display a message to the visitor, then redirect to the new domain.
posted by netbros at 8:13 AM on April 25, 2009


I believe you could use PHP or another server-side language to check the http REFERRER header and output your text to the top of the page. Shouldn't be difficult at all. You'll also want to have a way to check your logs to see how many people are still using the old URL so you know when you can kill the old domain.
posted by zachlipton at 8:15 AM on April 25, 2009


Hmm, I was hoping to avoid adding to the URLs (I like to stick to the pretty http://domain/folder_as_page_name/ type urls -- even seeing an index.html bugs me) or using JS for the actual redirect. (It is cleaner to do it in apache).

I will look into the referrer angle.

Thanks for the tips.
posted by cayla at 8:50 AM on April 25, 2009


Adding a fragment identifier (e.g. #moved) to the end then that'd be safer than a query string, and could be detected (and removed I suppose) by JavaScript.
Alternatively, use PHP to send the redirect and also make it set a cookie. On the new domain you could then include a JavaScript file, image or iframe loaded from the old domain, using PHP to detect the cookie, display a message and delete the cookie.
posted by malevolent at 9:43 AM on April 25, 2009


Couldn't you just rewrite the old url to something like http://newurl.com/index.php?redirected=true ?
It would be trivial then to add a line of scripting to the page to check for that GET parameter and output an additional message..


The problem with this approach is that are then going to bookmark THAT url, redirect parameter included. So you'll be outputting the message every time they visit.

A better, yet more complicated method, is to globally:

- Detect 'redirect=true' and pass off to a special handler
- In the handler, set a session variable that marks this request as a redirect
- Redirect again to the page w/o the 'redirect' parameter.
- In the page, check the session variable, output a message, and unset it.
posted by sbutler at 12:54 PM on April 25, 2009


I don't think the referrer will work -- any referrer header will be the page before the redirect.

sbutler's method is it. You have to make some state out of a stateless protocol. My inclination would be to do this client side (set a cookie on ?redirected=true, modify document.location, interrogate cookie) to lighten the server load, but either way will work.
posted by yt at 1:06 AM on April 26, 2009


Thank you very much for the feedback everyone. I am going to give sbutler's idea to twirl and see how it goes.
posted by cayla at 6:23 AM on April 26, 2009


« Older Help choosing a good women's w...   |  How to be charming.... Newer »
This thread is closed to new comments.


Post