1

If I write:

<?php
echo "SCRIPT_NAME: ".@$_SERVER['SCRIPT_NAME']."<br />";
?>

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:

http://example.com/foo

http://example.com/bar

http://example.com/hdhd

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?

  • What would you like to be done ? if index.php redirect to 404, other query serve the file ? – Dom Aug 3 '13 at 13:01
1

The Apache variable you want is called %{SCRI­PT_­FIL­ENAME}.

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.

  • yes, with SCRIPT_FILENAME works like I expected. – Jvrq Aug 6 '13 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.