的.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^cars/(.*).html$ /control.php [P,L]
RewriteRule ^trucks/(.*).html$ /control.php [P,L]
/control.php
<pre>
<?php
echo "Path Requested: " . $_SERVER['REQUEST_URI'] . "\n\n";
print_r($_SERVER);
?>
</pre>
测试网址(真实主机名替换为“example.com”)
http://example.com/trucks/valugatah.html
结果
Path Requested: /control.php
Array
(
[CONTEXT_DOCUMENT_ROOT] => /home/fubelboobin/public_html
[CONTEXT_PREFIX] =>
[DOCUMENT_ROOT] => /home/fubelboobin/public_html
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,gl;q=0.6
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_CONNECTION] => close
[HTTP_HOST] => fubelboobin.com
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
[HTTP_X_FORWARDED_FOR] => 23.241.124.74
[HTTP_X_FORWARDED_HOST] => fubelboobin.com
[HTTP_X_FORWARDED_SERVER] => fubelboobin.com
[PATH] => /bin:/usr/bin
[QUERY_STRING] =>
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 166.62.119.108
[REMOTE_PORT] => 47854
[REQUEST_METHOD] => GET
[REQUEST_SCHEME] => http
[REQUEST_URI] => /control.php
[SCRIPT_FILENAME] => /home/fubelboobin/public_html/control.php
[SCRIPT_NAME] => /control.php
[SERVER_ADDR] => 166.62.119.108
[SERVER_ADMIN] => webmaster@fubelboobin.com
[SERVER_NAME] => fubelboobin.com
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[UNIQUE_ID] => WfUhgaY@d2wAACMqjNMAAAAF
[PHP_SELF] => /control.php
[REQUEST_TIME_FLOAT] => 1509237121.06
[REQUEST_TIME] => 1509237121
[argv] => Array
(
)
[argc] => 0
)
请注意,浏览器地址栏中可见的网址是(正如预期的那样):
http://example.com/trucks/valugatah.html
那么问题是什么?
我希望$_SERVER['REQUEST_URI']
与我在地址栏中看到的相同,但是/trucks/valugatah.html
的原始网址,正如您从我发布的结果<中看到的那样/ strong> $_SERVER['REQUEST_URI']
正在返回/control.php
这应该不是问题,因为根据the docs,如果$_SERVER['REQUEST_URI']
被覆盖,那么我应该有权访问一个名为$_SERVER['REDIRECT_REQUEST_URI']
的新var(自动创建)保留原始$_SERVER['REQUEST_URI']
但正如您从结果中看到的那样,$_SERVER['REDIRECT_REQUEST_URI']
永远不会被创建。
我已经阅读了过去2天我能找到的所有内容,但我什么都没有......
答案 0 :(得分:0)
从.htaccess文件中删除“P”标志解决了这个问题。这是工作代码:
<强>的.htaccess 强>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^cars/(.*).html$ /control.php [L]
RewriteRule ^trucks/(.*).html$ /control.php [L]