2009-10-13 68 views
2

除了通過我的域名進行網絡訪問外,我的ISP允許通過以下格式訪問我的網站:user.hostname.com,其中user是我的登錄名,hostname是我的ISP。我已經寫了重寫規則,自動將user.hostname.com重新映射到www.mydomain.com,這很好。然而,事實證明,我查看我的網站上的統計數據,我的ISP要求我訪問user.hostname.com/stats/index.html。隨着我的重寫規則,這將改爲www.mydomain.com/stats/index.html,我無法訪問統計頁面。允許網址避開.htaccess中的mod_rewrite規則

有什麼辦法可以讓user.hostname.com/stats通過不變,同時仍然重寫所有其他user.hostname.com請求?

謝謝。

回答

4

如果使用Apache 2.2+試試這個:

RewriteRule ^/stats(|/.*)$ - [last] 
# After that the other rewrites... 

對於Apache 2.2 mod_rewrite的似乎不支持 ' - ' 的替代模式(DASH)。在這種情況下,請使用以下規則:

RewriteRule ^/stats(|/.*)$ /stats$1 [last] 
+0

謝謝。剛剛嘗試了您的建議,但它給出了一個服務器配置錯誤的錯誤。 有沒有其他想法? – James 2009-10-13 16:56:25

+0

適用於我,使用Apache 2.2.11。你使用的是什麼Apache版本?如果你有其他的RewriteRules工作,你可以在這裏粘貼一些示例conf? – 2009-10-14 13:28:44

+0

只有ISP發佈的信息是Debian Linux 4.0 Apache。 rewritecond%{http_host}^user \ .hostname \ .com [nc] rewriterule ^(。*)$ http://www.mydomain.org/$1 [r = 301,nc] rewritecond%{http_host}^www \ .hostname \ .com [nc] rewriterule ^(。*)$ http://www.mydomain.org/$1 [r = 301,nc] rewritecond%{http_host}^mydomain \ .org [nc] ] rewriterule ^(。*)$ http://www.mydomain.org/$1 [r = 301,nc] rewritecond%{http_host}^mydomain \ .com [nc] rewriterule ^(。*)$ http ://www.mydomain.org/$1 [r = 301,nc] rewritecond%{http_host}^www.mydomain \ .com [nc] rewriterule ^(。*)$ http://www.mydomain.org/$ 1 [r = 301,nc] – James 2009-10-14 16:54:18