2010-06-03 133 views
0

所有的意見在網上說事: 重寫URL 301-A URL-B如何使用mod_rewrite從一個頁面重定向到另一個頁面?

但如果我打開mod_rewrite的,將無法正常工作與RewriteEngine敘述上

所以,我(似乎?)糟糕的正則表達式,但不應該在這裏需要它。我該怎麼辦:

RewriteCond %{HTTP_HOST} ^untamed-adventures.com/travel/How/tabid/58/Default.aspx [NC] 

RewriteRule ^(.*)$ http://untamed-adventures.com/ [R=301,L] 

回答

0

%{HTTP_HOST}擴展到請求的主機,所以它永遠不會匹配untamed-adventures.com/travel/How/tabid/58/Default.aspx,只有untamed-adventures.com

如果你要轉發http://untamed-adventures.com/travel/How/tabid/58/Default.aspxhttp://untamed-adventures.com/,試試這個:

RewriteCond %{HTTP_HOST} =untamed-adventures.com 
RewriteRule ^/travel/How/tabid/58/Default.aspx$ http://untamed-adventures.com/ [R=301] 

L標誌是多餘的;前鋒總是最後的。

+0

啊,RewriteRule位工作除了一個必須刪除領導/ 非常多! – Dan 2010-06-07 06:03:41

+0

@Dan只有在.htaccess中或如果你設置了'RewriteBase /' – Artefacto 2010-06-07 06:18:13

+0

啊哈!是的,在.htaccess中。 – Dan 2010-06-07 07:41:59

0

一點也不清楚你想要做什麼。 HTTP_HOST是請求的URL中的主機名部分,在這種情況下是「untamed-adventures.com」,因此RewriteCond永遠不會匹配。

認爲你試圖做的是:

重定向301 /travel/How/tabid/58/Default.aspx http://untamed-adventures.com/

在這種情況下,不需要的mod_rewrite在所有。

+0

該文件中還有其他需要mod_rewrite的指令。 – Dan 2010-06-04 03:38:01

相關問題