2013-11-02 45 views
0

我是新的在Apache上使用mod_rewrite引擎,雖然我對正則表達式有一些基本的瞭解。但是,我感到困惑,並且在重定向不能正常工作時變得中風。重定向與mod_rewrite無法正常工作

這裏是我的.htaccess文件中的相關代碼:

RewriteCond %{REQUEST_URI} ^/vacations/([^/]*)(.*)$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

當我重定向,沒有什麼$ 2中。 $ 0和$ 1都包含整個匹配的字符串。例如,如果原始網址是/ vacations/asia/rar,我將被重定向到http://www.example.com/vacations/asia/rar而不是www.example.com/asia。

任何幫助將不勝感激。

回答

0

這是因爲你使用RewriteRule backreferences($ 1)當您應該使用RewriteCond backreferences(%1):

RewriteCond %{REQUEST_URI} ^/vacations/([^/]*)(.*)$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/%1 [R=301,L]