Returning a 302 (temporary) rather than 301 (permanent)
| Project: | Global Redirect |
| Version: | 6.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Hi
I've recently migrated a site from an old static HTML setup to Drupal. I'm using Global Redirect to send traffic from the old URLs (in the format /examplepagehere.html) to new Drupal SEO-friendly URLs (/example-page-here). There's only about 20 pages indexed, so I can do that manually.
It's only a small issue but the redirects are being returned as 302 rather than 301. I saw that this was sometimes an issue on IIS, but I am on an Apache/Debian server (Dreamhost to be precise). Any ideas if it something wrong in Global Redirect, Drupal, Apache, or what?
I'm on Drupal 6.8, and I've got the most recent dev version of Global Redirect because I needed the case sensitive patch too.
Many thanks
Dan

#1
Do you have a live example site I could take a peek at please (either post here or send to me via contact form...)
Cheers
#2
Sure - http://www.mawbeygp.co.uk
#3
Cheers
GlobalRedirect's purpose is to redirect system URL's to alias URL's... In the follow example you can see GR *is* working on your website.
pc:~ nthompson$ curl -I http://www.mawbeygp.co.uk/node/100HTTP/1.1 301 Moved Permanently
Date: Sat, 10 Jan 2009 00:13:02 GMT
Server: Apache/2.2.9 (Unix) PHP/4.4.9 mod_ssl/2.2.11 OpenSSL/0.9.8c mod_fastcgi/2.4.6 Phusion_Passenger/2.0.5 DAV/2 SVN/1.4.2
X-Powered-By: PHP/5.2.6
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0
Set-Cookie: SESS821ba301e85b69908507e4d27bcd612d=0k7rck62v0vp4dpehd46mdsea0; expires=Mon, 02 Feb 2009 03:46:22 GMT; path=/; domain=.mawbeygp.co.uk
Last-Modified: Sat, 10 Jan 2009 00:13:02 GMT
Location: http://www.mawbeygp.co.uk/registering.htm
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
How are you doing the page redirects? Could you provide an example of a failing redirect?
#4
I'm using HTTP Fox in Firefox, and when I click on the relevant search result on Google, HTTP Fox returns the status 'HTTP/1.1 302 Moved Temporarily'.
Perhaps I'm looking at the wrong line in HTTP Fox then?
#5
If it's of any help, I've attached a screendump of the HTTP Fox output.
#6
The URL http://www.mawbeygp.co.uk/c/registration isn't redirecting at all for me...
Are you sure that redirect isn't being handled by PathRedirect module?
#7
Hi guys,
I'm also having problem with 301 redirect, it returns 302 instead.
FYI, I'm using Drupal 6.9, Global Redirect 6.x-1.2 and Path Redirect 6.x-1.0-beta1 modules (all latest) and checked the link using http://web-sniffer.net/
example:
old url = http://www.nontonbioskop.com/index.php/news/1997
new url = http://www.nontonbioskop.com/news/statham-siap-main-dalam-transporter-3
url alias = "news/statham-siap-main-dalam-transporter-3" ---> node/1997
path-redirect = "index.php/news/1997" ---> node/1997 --- type: 301
This is the right setup right? I dont know whether this is a GR issue or path_redirect though..
#8
Can you please try disabling Path Redirect and just see what happens if you access node/1997? According to Curl, even that returns 302...
$ curl -I http://www.nontonbioskop.com/node/1997HTTP/1.1 302 Found
Date: Sun, 15 Feb 2009 10:42:39 GMT
Server: Apache
X-Powered-By: PHP/5.2.0-8+etch13
Set-Cookie: SESS8dfbb3e48c4ba10c634ebefc8b0ebbbc=a52c04e1f1e9e9fec0b8973a11f9f53d; expires=Tue, 10 Mar 2009 14:15:59 GMT; path=/; domain=.nontonbioskop.com
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Sun, 15 Feb 2009 10:42:39 GMT
Cache-Control: store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Content-Type: text/html; charset=utf-8
Location: http://www.nontonbioskop.com/news/statham-siap-main-dalam-transporter-3
... Accept-Encoding
Now GR as a module TELL's drupal to issue a 301... Therefore I'd imagine that if your server is issuing 302's instead there is either a bug in Drupal or an issue with your server config... I'D GUESS...
#9
Okay after I disabled Path Redirect, the result is still 302.
So what does it mean? my server issue?
Oh and I notice the function drupal_goto has a default 302 function parameter... I hope the bug isnt in there..
#10
This is the full result:
old url = http://www.nontonbioskop.com/index.php/news/1997
new url = http://www.nontonbioskop.com/news/statham-siap-main-dalam-transporter-3
Path Redirect ON:
old url = 302
new url = 200
node/1997 = 302
Path Redirect OFF:
old url = 200 (I'm confused, shouldn't this be 404?)
new url = 200
node/1997 = 302
#11
Whenever Global Redirect uses drupal_goto, it's done like this:
<?phpdrupal_goto('', $query_string, NULL, 301);
?>
Note the 301 being passed to drupal_goto.
What Server stuff you running? I'm guessing Ubuntu due to the "etch13" part of the PHP 5.2.8 header...
#12
My hosting is running Debian
#13
Anyone know a solution to this? (Btw, I tried to use .htaccess 301 redirect, and it redirects just fine)
#14
I'm at a loss. Global Redirect TELLS Drupal to do a 301 redirect. There is only (AFAIK) one known bug with Drupal using the 'REQUEST_URI' which breaks some redirects, but this only happens on ISS... See #348872: Add REQUEST_URI compatibility for IIS ISAPI_Rewrite for more information on that.
What happens if you have a clean drupal install on your server running, say, just the path and Global Redirect modules? Does that still throw 302's?
#15
Mm...I guess I'll have to try this if there's no other way hehe..
Is there any way I can debug how many and what params that drupal_goto function got called? Does putting print('function called with code:'.$redirect_code) in top of the drupal_goto function works?
#16
you could add a line at the top of drupal_goto, yes...
<?phpprint_r(func_get_args());
exit;
?>
Note... Making this change will remove the website's ability to redirect! You'll need the exit otherwise it will redirect before you get a chance to read the output...
#17
Heh...finally after debugging it, I found the real problem (at least for me)..
in drupal_goto function:
header('Location: '. $url, TRUE, $http_response_code);I change it to:
if ($http_response_code == 301) {header('Location: '. $url, true, 301);
header('Status: 301 Moved Permanently');
}
else
{
header('Location: '. $url, TRUE, $http_response_code);
}
After that, I got the 301 redirects as intended.
Note that the header("Status..") line is after setting the location header. Usually in all references I read, they set it before setting location header, but it's not working in my case (I think it's related to using cgi/fastcgi and/or running on debian server).
Thanks a lot for your help and patience, nicholas!
Cheers