0

.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]

/控制.php

<pre>
<?php
    echo "Path Requested: " . $_SERVER['REQUEST_URI'] . "\n\n";
    print_r($_SERVER);
?>
</pre>

测试 URL(真实主机名替换为“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
)

请注意,浏览器地址栏中可见的 url 是(如预期和期望的那样):

http://example.com/trucks/valugatah.html

所以有什么问题?

我希望它$_SERVER['REQUEST_URI']与我在地址栏中看到的相同,但这是原始 url /trucks/valugatah.html,正如您从我发布的结果 $_SERVER['REQUEST_URI']中看到的那样正在返回/control.php

这应该不是问题,因为根据文档,如果$_SERVER['REQUEST_URI']被覆盖,那么我应该可以访问一个名为的新 var(自动创建)$_SERVER['REDIRECT_REQUEST_URI'],该 var 保留原始$_SERVER['REQUEST_URI']但从我的Result中可以看到,$_SERVER['REDIRECT_REQUEST_URI']永远不会被创建。

在过去的两天里,我已经阅读了所有能找到的东西,但我什么也没有……

4

1 回答 1

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]
于 2017-10-30T21:36:19.753 回答