Forum Moderators: phranque

Message Too Old, No Replies

.htaccess passing variables and meta redirect

mod_rewrite questions

         

moonlightinred

3:11 pm on Feb 6, 2008 (gmt 0)

10+ Year Member



I specifically joined because I came across a similar question via a Google search, and you guys really know what you're talking about. I'm relatively new to PHP and using mod_rewrite, but I've implemented a few basic commands before (but only on a need basis, so I'd simply search the web until I found what I needed).

Anyway, I am in the process of restructuring a 500+ page site for a non-profit organization. This includes renaming files, creating and moving directories, and moving existing files into new sections. In short - a lot of bookmarks are going to be out of date very quickly and navigation will have changed. While this isn't the best course of action, it's necessary.

What I'd like to do is use an .htaccess file in the root to redirect users to any of the moved pages. Okay, no big deal. The problem is that I really want them to pass through a gateway page FIRST that lets them know the page has been moved and that they should update their bookmarks. Example:

1.) user goes to [mysite.com...]

2.) .htaccess redirects them to [mysite.com...] where they are told of the moved page and asked to update their bookmarks

3.) in 15 seconds, the meta refresh on redirect.php sends them to [mysite.com...]

Now, it seems to me that it would be possible to do this all fairly dynamically. Again, I have very limited experience in both .htaccess and PHP, so try not to laugh to hard at what I came up with:

.htaccess is:
RewriteEngine On
RewriteRule ^oldfolder/oldfile.html$ /redirect.php?to=newfolder/newfile.html

redirect.php (in the root) has these bits of code (the rest is standard HTML):

<meta http-equiv="refresh" content="15;URL=$_GET['to']">

with a paragraph in the body that says "This page has recently moved. You will be redirected to the new page in 15 seconds. Please bookmark the new page accordingly, as this a permanent change. Thank you for your understanding."

Do you see where I'm going with this? I really want to avoid using a dummy page for each changed page with a specific meta redirect. That would involve a lot of time and a lot of unnecessary (or so I see it) files cluttering up the webspace. Suggestions? I realize I'd probably be better off if I went through some tutorials, but at the moment I don't have a lot of time to do that, and even then, I think this is a pretty specific bit of coding. ANY help you can provide would be much appreciated...thanks!

wilderness

3:18 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What I'd like to do is use an .htaccess file in the root to redirect users to any of the moved pages.

This concept is almost as bad a meta-refresh problem your attampting to correct.

Just use this

[R=301,L]

at the end of your rewrtites and let the visitors browser solve the issue.

moonlightinred

4:12 pm on Feb 6, 2008 (gmt 0)

10+ Year Member



^ How does that solve my problem? Granted, I'm new to this, but wouldn't that just make it clear that the redirect is permanent? That's not my concern, really...my concern is how to get people to update their bookmarks. This site has a lot of very important information for a set group of people, and the information is updated on a fairly regular basis (3-4 times per week). I'm specifically trying to take care of people who have bookmarked pages, not the casual search engine user.

wilderness

5:14 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



^ How does that solve my problem? Granted, I'm new to this, but wouldn't that just make it clear that the redirect is permanent? That's not my concern, really...

Many websites utilize a 404 that says UPDATE your bookmark here. (per each removed page)

my concern is how to get people to update their bookmarks. This site has a lot of very important information for a set group of people, and the information is updated on a fairly regular basis (3-4 times per week). I'm specifically trying to take care of people who have bookmarked pages, not the casual search engine user.

You could try knocking on their door and informing them that if they don't update their bookmarks by a specific date that you are going to burn their house down ;)

Joking aside. . .there's no way to force a person or web browser to update bookmars (although some browsers have such a utility).
Some webmasters simply have these tools for bookmarks, which make frequent automated requests for pages the browser owner is not even viewing, denied access from their website.
Nor may you require a user to utilize a specific browser.
Additionally, there is no way to require (no matter how focused or competent they may be) that users view your emails in a specific format (html).

If they want to?
They will.

Here's some food for thought:
(sorry Jim Archive org having a bad day)
[clickz.com...]

moonlightinred

9:12 pm on Feb 6, 2008 (gmt 0)

10+ Year Member



Well, I know I can't FORCE them to update bookmarks (and that's not really my goal). My goal is to tell them the page has moved and unless they want to sit there for 15 seconds every time they try to access the old page, they're going to have to update their bookmarks. I guess my question is more this:

Can you pass a variable from .htaccess to a PHP page? Because to make my life easier, I'd like to be able to keep all my old pages and new pages links within .htaccess and just pass the information along to the non-specific PHP notification page when necessary. Is passing variables from .htaccess to a PHP page using $_GET even possible? If it is, how do I do it?

wilderness

9:16 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[google.com...]

moonlightinred

9:57 pm on Feb 6, 2008 (gmt 0)

10+ Year Member



Nevermind, guys, I figured it out. Thank you for your help and suggestions. For future reference, what I did is below.

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^oldfolder/oldpage.html$ redirect.php?to=newfolder/newpage.html [R=301,L]

redirect.php

<meta http-equiv="refresh" content="1;URL=<?php echo $_GET['to']?>">

Pretty simple when I finally figured out what I wanted it to do...worked like a charm. Thanks!

phranque

1:08 am on Feb 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



a better way to do this is to send a Location: HTTP response header [w3.org] instead of a document containing a meta-refresh.

in php:
header ("location: $_GET['to']");

jdMorgan

3:35 pm on Feb 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My impression is that moonlightinred wants to serve the page with the meta-refresh as an interstitial. I don't like meta-refreshes either, but if you want to briefly present a page that explains what's going on, then a meta-refresh or client-side JS is about all you can do.

Jim

moonlightinred

7:47 pm on Feb 7, 2008 (gmt 0)

10+ Year Member



^^ I'll look into that.

^ Exactly...I know there isn't a "correct" way to do this, because by its very nature, I can't follow the rules and have this happen. JavaScript is out of the question because out of the people I know, as many have it disabled as don't.

Again, all, thanks for the input. Any other suggestions are welcome!

g1smd

10:15 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't like the interstitial page. Note that the PageRank of the old pages is not passed on to the new pages through that meta refresh. That is a big problem.

A straight 301 redirect is the best way to tackle this. It matters not whether people update their bookmarks, because you will leave the redirect up permanently.

People will gradually update them over time when they see that the URL has changed.

jdMorgan

12:56 am on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, a 301 is better, and can easily be served to known/important search engine robots instead of the interstitial page. :)

And that's what I do. For those who are concerned about "cloaking," there's no intent to deceive anyone, and the site has been hand-inspected many times by the SEs (because I often use it to show them their crawler problems). It hasn't been banned yet, even with all that attention from the guys with the "big red button" close to hand.

This is simply user-agent-variant content, and the "Vary" server response header says as much. The intent is to get the "control element" of the client to update the URL, which is accomplished by asking the human user to do so if the client is a browser, or by issuing a 301 redirect if the client is a robot. Slightly different "client control elements," slightly different "protocols" used.

I don't often do this meta-refresh/cloaked-301, but if you saw the site and the specific application of this method, you'd likely agree that it was necessary for usability, and also fairly effective. Because our sites and user bases are all different, everyone's mileage may vary -- Sometimes "Click here" is the best anchor text. ;)

Jim