send REQUEST_URI with header location redirect via settings.php I'm in predicament where I must use settings.php to do what I'd normally just do via mod_rewrite... the site is being hosted on Pantheon and I am referring to this article: http://helpdesk.getpantheon.com/customer/portal/articles/368354

I need to send the original requested path for reference. Trying to pass a the SERVER_URI as a parameter via header location in setting.php gets me an infinite loop. 

My code:

if (preg_match('/article\/[0-9]?[0-9]\/[0-9]?[0-9]\/[aA-zZ].+/', $_SERVER['REQUEST_URI'])) {
    header('HTTP/1.0 301 Moved Permanently');

    header("Location: http://answers3x-ec-core-community.gotpantheon.com/catchall/?dest=" . urlencode($_SERVER["REQUEST_URI"]));  exit;
}


Anybody have any suggestions as to how I might accomplish passing the $_SERVER["REQUEST_URI"] via header location from settings.php without an infinite loop?
While it's technically possible to use Drupal contrib to perform the redirect, it's faster and more efficient to redirect without having to fully bootstrap your web application.

For web only actions, like redirects, check for the existence of $_SERVER['PANTHEON_ENVIRONMENT'] - if it exists, it will contain a string with the current environment (dev, test or live).

To perform redirection for the pattern you've supplied, make sure to only match for it at the beginning of the URI in order to avoid an infinite loop problem:

// Pantheon - web only.
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
    // Check if you only want redirection from the live web environment.
    if ($_SERVER['PANTHEON_ENVIRONMENT'] == 'live') {
        if (preg_match('/^\/article\/[0-9]?[0-9]\/[0-9]?[0-9]\/[aA-zZ].+/', $_SERVER['REQUEST_URI'])) {
            header('HTTP/1.0 301 Moved Permanently');
            header('Location: http://answers3x-ec-core-community.gotpantheon.com/catchall/?dest=' . $_SERVER["REQUEST_URI"]);
            exit();
        }
    }
}


Sources: 

Configuring settings.php

PHP preg_match() Examples

preg_match