2016-04-10 17 views
1

在相關的Apache虛擬主機配置我有以下幾點:如何理解這些mod_rewrite日誌文件條目?

<Directory "/var/www/html/path"> 
    RewriteEngine on 
    RewriteBase/
    RewriteRule ^go\.html$ /out/qs.html?name=value 
</Directory> 

這裏是qs.html文件的內容:

<html> 
<head><title>Query String</title></head> 
<body> 
    <h2>Query String</h2> 
    <script> 
    document.write("<p>Query String: " + window.location.search.substring(1) + "</p>"); 
    </script> 
</body> 
</html> 

當我發送一個HTTP請求到服務器的/ path/go.html(沒有任何附加的查詢字符串),返回文檔,但在qs.html文檔的呈現中沒有看到查詢字符串。我期望看到「name = value」查詢字符串。

這裏與絨毛去除和行號的日誌文件添加相關線路:

1. [perdir /var/www/html/path/] strip per-dir prefix: /var/www/html/path/go.html -> go.html 
2. [perdir /var/www/html/path/] applying pattern '^go\\.html$' to uri 'go.html' 
3. [perdir /var/www/html/path/] rewrite 'go.html' -> '/out/qs.html?name=value' 
4. split uri=/out/qs.html?name=value -> uri=/out/qs.html, args=name=value 
5. [perdir /var/www/html/path/] trying to replace prefix /var/www/html/path/ with/
6. [perdir /var/www/html/path/] internal redirect with /out/qs.html [INTERNAL REDIRECT] 

其實線1通3是幾乎什麼我希望,如果它只是停在那裏,我認爲,我會理解的。我不明白的是爲什麼它從這一點繼續,剩下的三條線告訴我什麼。有人可以幫我理解這一點。我正在爲這件事撕碎我的頭髮。謝謝。

 ... doug 

回答

1

您需要引用可以在重寫規則中定義的標誌字符。

請參考https://httpd.apache.org/docs/current/rewrite/flags.html

另外,我可以看到他們是在你的概念有誤,如果你正在寫一個重寫規則,你不能讀通過JavaScript是客戶端生成的URL。

如果你真的想這樣做,你可以使用R標誌,它會重定向,但在這種情況下,重寫規則的目的將被擊敗。

+0

非常感謝!因此,基本上我認爲您所說的是,如果想要模糊特定URL已被重寫的事實,則需要服務器端支持。這是非常重要的一點。此外,它有很多意義。我想這是非常有道理的,每個人都只是假設用戶知道它。再次,非常感謝您的幫助。我很高興終於把這個問題拋在身後。 – user3311045