If I write:
echo "SCRIPT_NAME: ".@$_SERVER['SCRIPT_NAME']."
";
?>
SCRIPT_NAME: /index.php
The line above is showed.
I'm using these rewrite lines
RewriteCond %{SCRIPT_NAME} !^/index\.php$
RewriteRule .* http://example.com/404 [L]
I have checked:
The RewriteCond is matched then I'm being redirect to 404
[03/Aug/2013:13:07:48 +0200] [example.com/sid#23c3710][rid#263afe8/initial] (4) [perdir /var/www/vhosts/example.com/httpdocs/] RewriteCond: input='' pattern='!^/index\\.php$' => matched
[03/Aug/2013:13:07:48 +0200] [example.com/sid#23c3710][rid#263afe8/initial] (2) [perdir /var/www/vhosts/example.com/httpdocs/] rewrite '404' -> 'http://example.com/404'
[03/Aug/2013:13:07:48 +0200] [example.com/sid#23c3710][rid#263afe8/initial] (2) [perdir /var/www/vhosts/example.com/httpdocs/] implicitly forcing redirect (rc=302) with http://example.com/404
[03/Aug/2013:13:07:48 +0200] [example.com/sid#23c3710][rid#263afe8/initial] (1) [perdir /var/www/vhosts/example.com/httpdocs/] escaping http://example.com/404 for redirect
[03/Aug/2013:13:07:48 +0200] [example.com/sid#23c3710][rid#263afe8/initial] (1) [perdir /var/www/vhosts/example.com/httpdocs/] redirect to http://example.com/404 [REDIRECT/302]
But if I use example.com/index.php/nnn or
example.com/index.php
I'm still being redirected
[03/Aug/2013:13:10:41 +0200] [example.com/sid#23c3710][rid#263eff8/initial] (4) [perdir /var/www/vhosts/example.com/httpdocs/] RewriteCond: input='' pattern='!^/index\\.php$' => matched
[03/Aug/2013:13:10:41 +0200] [example.com/sid#23c3710][rid#263eff8/initial] (2) [perdir /var/www/vhosts/example.com/httpdocs/] rewrite '404' -> 'http://example.com/404'
[03/Aug/2013:13:10:41 +0200] [example.com/sid#23c3710][rid#263eff8/initial] (2) [perdir /var/www/vhosts/example.com/httpdocs/] implicitly forcing redirect (rc=302) with http://example.com/404
[03/Aug/2013:13:10:41 +0200] [example.com/sid#23c3710][rid#263eff8/initial] (1) [perdir /var/www/vhosts/example.com/httpdocs/] escaping http://example.com/404 for redirect
[03/Aug/2013:13:10:41 +0200] [example.com/sid#23c3710][rid#263eff8/initial] (1) [perdir /var/www/vhosts/example.com/httpdocs/] redirect to http://example.com/404 [REDIRECT/302
I can't see anything at input='', it is empty at each request. Then never will be different like the pattern, then always will match
Any suggestion?
Answer
The Apache variable you want is called %{SCRIPT_FILENAME}
.
In PHP's $_SERVER
super global, both SCRIPT_NAME
and SCRIPT_FILENAME
exist but in Apache, only %{SCRIPT_FILENAME}
exists.
It's not clear from the documentation exactly what each of the PHP variables contains but in my testing, SCRIPT_FILENAME
is a full filesystem path and SCRIPT_NAME
is either the path from the document root or the path component of the URL.
Comments
Post a Comment