2010-02-02 123 views
0

我需要複製mod_alias的功能,我不能直接使用它,因爲我在共享主機上,而且別名語句在.htaccess中不起作用。這個mod_rewrite語句有什麼問題?

我想達到什麼是本質

Alias /manual /www/customer/some_other_dir/manual 

我想mod_rewrite的:

RewriteRule ^/manual/(.*) /www/customer/some_other_dir/manual/%1?%{QUERY_STRING} [L] 

這永遠不會匹配任何調用www.example.com/manual

爲什麼不呢?我究竟做錯了什麼?

+0

@Pekka - 把這個生活之前檢查我的修訂! :P – 2010-02-02 22:57:47

回答

2

嘗試:

RewriteRule ^/manual(/(.*))?$ /www/customer/some_other_dir/$2 [L] 

?意味着可選除了在.的克林封閉的/角色,以確保/manual/manual//manual/a/b/c雖然我收集斜線通常是Apache預重寫添加發動機無論如何。

在我的箱子簡單的測試表明此規則也通過查詢字符串:

/manual/a/b?c=d -> /www/customer/some_other_dir/manual/$2 
+0

請注意,這也會匹配'/ manualasdf'! – Aistina 2010-02-02 22:55:33

+0

@Aistina - 好點!,抓住了!將修改;) – 2010-02-02 22:56:38

+0

好了,謝謝修改! – 2010-02-02 22:58:20

1

屯關MultiViews選項

Options -Multiviews 

,我認爲,這是期待/在請求的URL的結尾。

這樣的事情也會匹配www.example.com/manual

RewriteRule ^/manual/?(.*) /www/customer/some_other_dir/manual/%1?%{QUERY_STRING} [L]