Atara Atara - 4 months ago 30
PHP Question

Why do I get empty $REQUEST_URI after .htaccess redirection

I tried to customize the instructions in http://alistapart.com/article/succeed
to my needs - redirect all *.html pages into dispatcher.php file that parses the URL.

in my .htaccess file, I added

RewriteRule ^(.*)\.(html)$ dispatcher.php [L,NC]


but all the parameters in dispatcher.php are empty:

echo "1. " . $REQUEST_URI . "<br />";
echo "2. " . $DOCUMENT_ROOT . "<br />";
echo "3. " . $SCRIPT_FILENAME . "<br />";


Why dont I get these parameters?




meanwhile I avoid the problem by using the following:
in .htaccess -

RewriteRule ^(.*)\.(html)$ dispatcher.php?u=$1 [L,NC]


and in dispatcher.php -

$u = $_GET['u']; // and use this $u parameter . . .





original sample code:

RewriteRule !.(gif|jpg|png|css)$ /your_web_root/index.php # in .htaccess



if(file_exists($DOCUMENT_ROOT.$REQUEST_URI)
and ($SCRIPT_FILENAME!=$DOCUMENT_ROOT.$REQUEST_URI)
and ($REQUEST_URI!="/")){ . . . // in index.php

Answer

$REQUEST_URI, $DOCUMENT_ROOT... are not variables!

you should use

$_SERVER['REQUEST_URI']
$_SERVER['DOCUMENT_ROOT']
...

p.s. you can simply:

var_dump($_SERVER);