简体   繁体   中英

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

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

you should use

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

ps you can simply:

var_dump($_SERVER);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM