2010-05-21 90 views
0

這是這個問題的後續:Rewrite URL - how to get the hostname and the path?mod_rewrite的重寫規則不工作

我得到這個重寫規則:

RewriteEngine On 
RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl 

這似乎是正確的,正是我需要的。但它在我的服務器上不起作用。我收到一個404頁面未找到錯誤。

mod_rewrite的啓用,如下面的簡單規則是工作的罰款:

RewriteEngine On 
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L] 

你能幫忙嗎?

謝謝

+0

ServerFault問題,大概。 – 2010-05-21 09:44:48

+0

你嘗試了什麼URI? – Gumbo 2010-05-21 11:43:34

回答

0

它認爲這是不正確的。你不能使用url作爲RewriteRule的第一個操作數。

你應該寫的,而不是

RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl 

是什麼(編輯:您要到最後部分路徑匹配某種原因,我會責成)

RewriteCond %{HTTP_HOST} !="" 
RewriteRule ^/(.*?)([^/]+)(?:/)?$ http://www.xmldomain.com/bla/page?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl%2A [QSA,B,P,NE] 

還要注意的是重寫規則不會被虛擬主機自動繼承。您必須明確激活繼承。

+0

好的。但這並不能幫助我解決問題。我需要分別在最後一個斜槓(「頁面」)之後捕獲字符串。 的subsitution部分應該是這樣的: HTTP://www.xmldomain.com/bla/$2?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl 如何模式部分看起來像這樣做? – 2010-05-21 10:25:19

+0

這是我的錯,我提供了正則表達式。正則表達式是否對變量進行操作? – 2010-05-21 15:16:25

+0

@ buggy1985確定,那麼$ 1是多少? – Artefacto 2010-05-21 15:26:14

0

也許嘗試這個

RewriteRule ^/(.+)/page/([^/]+)/(.*)$ domain/index.php?page=$2&host=%{HTTP_HOST} [QSA,NC,L]