Hi,
I am doing some maintenance on a site which does not use index.php as the root script (They have renamed it to index_drupal.php) and have been having problems with the Redirect module not redirecting. I have tracked it down to the following code in redirect.module:
function redirect_can_redirect() {
$can_redirect = &drupal_static(__FUNCTION__);
if (!isset($can_redirect)) {
$path = current_path();
$can_redirect = TRUE;
if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php') {
// Do not redirect if the root script is not /index.php.
$can_redirect = FALSE;
}
...
If I comment out this line so that $can_redirect does not get set to FALSE, the redirect completes as expected.
I don't mind "hacking" the module in this instance just to get the job done, but I would be concerned about any possible implications of doing this. Does anyone know *why* redirecting is disabled in this situation? What is this test for? Some kind of security check?
Is it safe to just replace the index.php check with a check for index_drupal.php? Or just to comment out the $can_redirect = FALSE line?
Thanks very much,
Andy
Comments
Comment #1
NoahJ commentedI'd like to chime in and say I'm wondering the same thing. Just had to comment out said line of code since I'm running Drupal in a subdirectory, so instead of the expected "/index.php", $_SERVER['SCRIPT_NAME'] returns "/subdir/index.php".
Thanks!
Comment #2
dave reid@NoahJ: Your issue will be resolved now that #1198028: Redirects do not work if $_SERVER['SCRIPT_NAME'] does not follow base_path is committed.
As far as using a non-standard index.php as the entry point, I would recommend just using a local patch to the code that removes this check in Redirect. It's not something we can really address from a generic standpoint in the module.
Comment #3
markusd1984 commentedIn my case, the check prevents the redirecting from working, even though my rewrite points to /index.php.
https://www.drupal.org/project/redirect/issues/2995563#comment-12760644
When I disable it my redirects get access and are working. Any ideas?