User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » .htaccess question Page [1]  
quagmire02
All American
44225 Posts
user info
edit post

is there a way to do a redirect with a notification page before they're redirected? i swear, i've googled and probably missed it because this seems like a downright useful implementation and i can't believe it's not possible

so let's say you have a site of 100 pages, and they're all found in the root...now you want to divide those into folders and rename the files as well...okay, that's easy enough to do, and i'd like to implement a 301 redirect

but i want the user to KNOW they've been redirected with a notice (something generic that does not specify the page) so that they'll update their bookmarks (i don't want to leave up the redirection permanently)...i would assume that, due to the nature of .htaccess, that this isn't possible, but am i missing something? is there an easy way to do this and i'm too blind to see or think of?

[Edited on February 4, 2008 at 3:37 PM. Reason : .]

2/4/2008 3:32:29 PM

qntmfred
retired
40555 Posts
user info
edit post

i knew i had seen this before

nothing in message_topic.aspx?topic=495017 helped?

you either have to turn all your old pages into meta refreshes or do a 301

[Edited on February 4, 2008 at 3:43 PM. Reason : you might be able to use mod_rewrite]

2/4/2008 3:41:14 PM

quagmire02
All American
44225 Posts
user info
edit post

^ ha...i couldn't remember if i'd posted this question before or not (that was almost 5 months ago!)

sadly, no...i mean, the pages with meta refreshes is what i've been using thus far, but i was hoping someone might have had a revelation

2/4/2008 3:46:03 PM

DirtyMonkey
All American
4269 Posts
user info
edit post

You can do this with mod_rewrite and a common redirect page.

RewriteRule /*your_matches_here /redirect.php?to=$1

redirect.php:
<meta .../>
You are being redirected to $_GET['to']. Please update your bookmarks, yadda yadda yadda.

2/4/2008 4:15:25 PM

mellocj
All American
1872 Posts
user info
edit post

You can't do that with a 301 redirect, by definition. A 301 redirect is a specific HTTP status code, it is not something that gets displayed in the browser.

2/4/2008 6:01:12 PM

mienutzich
All American
4300 Posts
user info
edit post

if these 100 pages or so have an included header or something you should just do a regular htaccess 301 redirect and then add some code in the header to detect if the page was redirected. Then you could add a notification somewhere on the page or a lightbox popup or something.

I wouldn't waste my time doing this unless the pages had a common include file.

2/4/2008 7:18:23 PM

quagmire02
All American
44225 Posts
user info
edit post

^^^ you inspired me, so i tweaked my code...this works perfectly, but if y'all can take a look at it and let me know if there are any glaring problems, security holes, etc., i'd appreciate it:

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'] ?>">

it does exactly what i want/need it to do...i have no idea why i couldn't find this anywhere else...seems like a useful bit of code, but i guess not

[Edited on February 6, 2008 at 5:02 PM. Reason : .]

2/6/2008 5:01:16 PM

mellocj
All American
1872 Posts
user info
edit post

the only problem is that its not a 301 redirect, so search engines will not follow the redirect or pass weight for the old page to new page.

2/6/2008 6:05:39 PM

DirtyMonkey
All American
4269 Posts
user info
edit post

^ true. i mean technically there is a 301 redirect, but it is to a page that does a meta refresh so there isn't much point.

the only other thing i can come up with is this:

htaccess
RewriteEngine On
RewriteRule ^/oldfolder/(.*) /newfolder/$1?r [R=301,L]

<Directory "/path/to/newfolder">
php_value auto_append_file redirect_check.php
</Directory>


redirect_check.php
<?php if(isset($_GET['r'])): ?>
<script type="text/javascript">
alert('You were redirected');
</script>
<?php endif; ?>


The limitation here is that unless the file that is being requested is a php file, that auto_prepend won't work. To get around this you could tell apache to process .html files as php scripts, but you might not want to do that. The upside is that you have a proper 301 redirect and no crappy meta-refresh. When you are done with the redirect, i.e. done supporting the old links, you can simply get rid of the auto_append_file line (there is also auto_prepend_file, which might be more useful depending on what you're doing).

2/7/2008 12:33:27 AM

mienutzich
All American
4300 Posts
user info
edit post

^ the only problem with that is search engines are going to bookmark the page as page.php?r instead of page.php

so the search engines are either going bookmark the wrong page altogether causing the popup to occur every time someone comes from a search engine or its going to double mark the page causing it to split its value between the real page and the one with the variable

You should be able to check one of the $_SERVER variables to see if this was a 301 redirect but I'm not really sure which one without looking it up. Then you just display the popup if its a 301.

2/7/2008 8:30:50 AM

mellocj
All American
1872 Posts
user info
edit post

^ yes you can check $_SERVER['HTTP_REFERER'] in php to see the page they were referred from. I think this would work, as google bot does not send pass referer info.

2/7/2008 12:55:13 PM

DirtyMonkey
All American
4269 Posts
user info
edit post

301 redirects don't send a referrer. it's part of the HTTP spec.

looks like you're just plain sol dude

2/7/2008 1:11:26 PM

lilbirdey
Starting Lineup
55 Posts
user info
edit post

Google for ErrorDocument

2/7/2008 1:56:17 PM

quagmire02
All American
44225 Posts
user info
edit post

bah...i know there's no real way to do this, at least not appropriately...but, the truth of it is that i don't really care about pagerank because these pages are buried pretty deeply and don't come up high on any search engine i've ever used

this notification will only be in place for 6 months, to give the plethora of people a chance to update bookmarks and any outside links...after that, i couldn't care less

thanks for all the input, though, i do appreciate it...anyone think using a response header might be a better option (location:$_GET[to])?

2/7/2008 2:50:30 PM

mienutzich
All American
4300 Posts
user info
edit post

Yeah what i was saying earlier was wrong. There isn't any way to see the referrer response codes, I was thinking of the access log.

htaccess
RewriteEngine On
RewriteRule ^/oldfolder/(.*) /redirect.php?r=$1 [R=301,L]

<Directory "/path/to/newfolder">
php_value auto_append_file redirect_check.php
</Directory>

redirect.php
<?php
session_start();
$_SESSION['redirected'] = true;
header("Location: /newfolder/".$_GET['r'],TRUE,301);
?>

redirect_check.php
<?php session_start(); if(isset($_SESSION['redirected'])): ?>
<script type="text/javascript">
alert('You were redirected');
</script>
<?php endif; ?>

This builds off what DirtyMonkey did earlier and prevents the wrong page from being bookmarked. Unfortunately you are now going through two 301 redirects.

2/7/2008 10:41:42 PM

 Message Boards » Tech Talk » .htaccess question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.