I'm not sure if this is a Redirect (http://drupal.org/project/redirect), or Boost problem - but I've just discovered that if I have a redirect which is highlighted by 'Redirect' as yellow and says that "this redirect overwrites and existing path' - then the redirect works the first time (A 301 moved permanently response). But a second visit to the redirected url returns HTTP/200 and shows a blank page that Boost is holding in its page cache - so no redirect occurs. :-(

For redirects that are not in the site's existing path - everything works fine.

Thoughts?

Here's the response header for a request to page http://www.58bits.com/photos/a-short-trip-to-savannakhet-laos which should be redirected, and which works fine for the first request (HTTP/301)

Server: Apache/2.2.22 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0,private
Last-Modified: Sun, 31 Mar 2013 20:27:07 +0000
Keep-Alive: timeout=15, max=100
ETag: "1364761627"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Date: Sun, 31 Mar 2013 20:27:07 GMT
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
X-Redirect-Id: 16
Content-Type: text/html
Location: http://www.58bits.com/photos/photos-of-savannakhet-laos

And here are the response headers for the second request (HTTP/200) - which is not redirected.

Server: Apache/2.2.22 (Ubuntu)
Content-Encoding: gzip
Vary: Accept-Encoding
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "63-4d93e53fafcc0;4d925a50db940"
Keep-Alive: timeout=15, max=100
Content-Length: 100
Expires: Sun, 19 Nov 1978 05:00:00 GMT
X-Cached-By: Boost
Date: Sun, 31 Mar 2013 20:32:45 GMT
Accept-Ranges: bytes
Connection: keep-alive
Content-Type: text/html; charset=utf-8

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Status: Active » Closed (works as designed)

Boost has been known to cache with a redirect module before, the redirect module should exit immediately after having sent the 302 header instead of getting to the boost hook on page output/ exit.

RewriteCond %{ENV:REDIRECT_STATUS} 200

should also skip boost in .htaccess but doesn't (sometimes), boost is known to work with url aliases/ global redirect/ fast404 e.g. other modules that output headers so really it's redirects problem. It may be temporarily solved by adding

RewriteCond %{ENV:REDIRECT_STATUS} 302 OR

above the 200 line in .htaccess and removing the cached file, which might (assuming that an internal redirect is set by the redirect module) skip all the boost rewrite rules and never present the blank page so it should go to index.php and drupal should work as normal but that's basically a guess because it's quite likely that boost is still going to generate that blank page until the redirect module is fixed.

anthony.bouch’s picture

Thanks Philip - that helps.

Best,

Tony

dadderley’s picture

I have the same problem on 2 sites.
In both cases I had to disable Boost.

Anonymous’s picture

Does the older module Global Redirect work ? (it used to), it's a redirect problem otherwise as explained before. You can get around this by writing a rewrite rule.

apemantus’s picture

Referenced here: #1957530: Redirect and Boost?

I'm having this problem as well; initially I thought it should be a Redirect issue, but now I'm not so sure. Redirect exits by calling drupal_exit, which seems correct, but which then triggers boost_exit.

However, redirect has set the header status to 301. So once $_boost['header_info'] = boost_get_header_info(); is called, can boost_exit then ignore all pages where $_boost['header_info']['status'] matches 301/302?

apemantus’s picture

Issue summary: View changes
Status: Closed (works as designed) » Active
furamag’s picture

I think apemantus is right. Boost should not create cache file if redirect status code set to 301 or 302. We don't need to cache redirect pages. I added following code to boost_exit function:

  // Skip writing data to a file if other module created redirect.
  $redirect_status_codes = array('301', '302');
  if (in_array($_boost['header_info']['status-number'], $redirect_status_codes)) {
    return;
  }

I added my code after following code:

  // Get header info.
  $_boost['header_info'] = boost_get_header_info();
  $_boost['matched_header_info'] = boost_match_header_attributes($_boost['header_info']);
  if ($_boost['matched_header_info']['enabled'] === FALSE) {
    return;
  }

Please test it and let me know if it works for you. If it works I will create patch then.

Dave Reid’s picture

If I'm not mistaken, shouldn't boost not apply if the $destination parameter passed to boot_exit() is not empty? Wouldn't that cover all redirect cases? Is there a valid reason we'd want Boost to cache any redirects of any kind?

chymz’s picture

I tried #7 but not working I think...

I can give my little workaround, in boost.module, line 307 (on DEV version)

I replace this :

if ($_boost['matched_header_info']['enabled'] === FALSE) {
    return;
}

By this :

$data_test = preg_replace('/[\s\r\n]+/Uims','', strip_tags($data));  
if ($_boost['matched_header_info']['enabled'] === FALSE || empty($data_test)) {
  return;
}

Hope this help...

Here is the original idea : https://drupal.org/node/1176534

azinck’s picture

I agree with Dave Reid in #8. The Boost module previously attempted to solve this problem in boost_drupal_goto_alter() but the redirect module doesn't call drupal_goto(). I don't see any reason not to move that logic into boost_exit(). Patch attached.

azinck’s picture

Status: Active » Needs review
FileSize
755 bytes

Previous patch had some whitespace cruft.

joelstein’s picture

Status: Needs review » Reviewed & tested by the community

Works for me!

apemantus’s picture

Yep - works for me to - this has been a bit of a pain this issue, as previously had to whitelist a ton of redirects. Thanks!

Anonymous’s picture

Version: 7.x-1.0-beta2 » 7.x-1.0
Status: Reviewed & tested by the community » Needs work

This patch hasn't been applied to Version 7.x-1.0 yet - only Beta 2 as it seems. The problem still exists in the current stable version.

swim’s picture

Priority: Normal » Major
Status: Needs work » Reviewed & tested by the community

Not sure what @14 is talking about :S.

Applies fine for me on both stable (1.0) & dev (1.x). Without the patch applied users requesting pages which redirect can be served up a blank page. This should hopefully be low hanging fruit for maintainers, patch works a treat.

Vacilando’s picture

Works perfectly for a long time on several sites; please apply to the dev version at least.

Vacilando’s picture

Could the maintainers please commit this to DEV? (One patch less to have to keep applying on multiple sites.)

bendev’s picture

This is working for my site as well.

Would appreciate to commit this...

makimaki’s picture

If I wanted to apply this speicifc patch to my stable version 7.x-1.0 inmy production site how would I go about doing this?

I am fairly new to drupal patches but I have some programming know how (just enough to be dangerous) I need this for my site and don't want to wait for SEO ressons when it's offically released.

As I currently understand this, I need to go to the boost module folder, find the file named boost.module and make some changes. If I am on the right path, what do I need to replace?

Any help appreciated.

aufumy’s picture

Makimaki

You can manually apply the patch by removing the lines that start with the minus sign: -
and adding the lines that start with the plus sign: +
in the order that the patch files shows

e.g. for the patch file https://www.drupal.org/files/issues/boost_redirect-1957532-11.patch, edit the boost.module and remove the entire function boost_drupal_goto_alter(), and add an if statement inside the function boost_exit()

More information: https://www.drupal.org/patch/apply

makimaki’s picture

Thank you. Thank you, aufumy. You are an angel. It works and I learned something new. It's not so difficult after all. Thanks once again.

akosipax’s picture

Patch applies cleanly on 7.x-1.0 and it fixes the problem.

joelstein’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#1176534: Bypass caching on redirects

I think we need to leave the implementation of hook_drupal_goto_alter(). Even though Redirect doesn't use drupal_goto(), lots of modules do, including core Search (see search_view() which uses drupal_goto() when visiting /search). See #1176534: Bypass caching on redirects.

pipicom’s picture

Had exactly the same problem. #11 solved it.
Thank you azinck.

azinck’s picture

Status: Needs work » Needs review
FileSize
1.02 KB
528 bytes

@joelstein. Good point. Patch updated to retain boost_drupal_goto_alter()

robertstaddon’s picture

Applying the patch from @azinck in #25 worked for me. Thanks!

RAWDESK’s picture

#25 fixed it for me too.

OWast’s picture

Status: Needs review » Reviewed & tested by the community

#25 solved the problem and is rolling without problems in production environment.

  • bgm committed f92721a on 7.x-1.x authored by azinck
    Issue #1957532 by azinck: Boost with Redirect Module and 301
    
bgm’s picture

Status: Reviewed & tested by the community » Fixed

Commited to 7.x-1.x.

Thanks! (and sorry it took so long

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jwilson3’s picture

I've rerolled the patch in #25 for a Drupal 6 site.