Atara Atara - 1 year ago 105
PHP Question

Why do I get empty $REQUEST_URI after .htaccess redirection

I tried to customize the instructions in
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

and ($REQUEST_URI!="/")){ . . . // in index.php

Answer Source

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

you should use


p.s. you can simply:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download