2017-10-29 40 views
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] 

/control.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] => [email protected] 
    [SERVER_NAME] => fubelboobin.com 
    [SERVER_PORT] => 80 
    [SERVER_PROTOCOL] => HTTP/1.1 
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache 
    [UNIQUE_ID] => [email protected] 
    [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']是相同正如我在地址欄,這是/trucks/valugatah.html原始URL但是,你可以從我的貼結果$_SERVER['REQUEST_URI']瞧瞧正在恢復/control.php

這應該不是問題,因爲根據the docs,如果$_SERVER['REQUEST_URI']被覆蓋,那麼我應該可以訪問一個名爲$_SERVER['REDIRECT_REQUEST_URI']的新var(自動創建),它保留原始$_SERVER['REQUEST_URI'],但正如您從我的中看到的那樣結果,$_SERVER['REDIRECT_REQUEST_URI']永遠不會被創建。

我讀了所有我能找到在過去的2天,我已經沒有什麼...

+0

可能是一些做的'P'標誌...你使用這裏反正是什麼,這不是一個標準的一部分「漂亮網址「設置... – CBroe

+0

@CBroe - 感謝您的想法!這工作。 – Pseudo

回答

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]