2016-10-13 172 views
2

我需要將一些頁面從一個頁面重定向到另一個頁面。例如: example.com/help/questions(/show/some_text|none|get params)example2.com/questions(/show/some_text|none|get params)Htaccess:將一些頁面從一個頁面重定向到另一個

的htaccess:

Redirect permanent /help/questions http://example2.com/questions 

但重定向從example.com/help/questions/show/some_text不工作 - 我有example2.com/help/questions/show/some_text代替example2.com/questions/show/some_text 有了這樣的代碼,我有一些問題。

RewriteCond %{HTTP_HOST} example.com/help/questions 
RewriteRule (.*) http://example2.com/questions/$1 [R=301,L] 

我該如何解決? 所有其他頁面正常重定向。

回答

1

%{HTTP_HOST}只匹配主機名稱不是URI。

您可以使用:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC] 
RewriteRule ^help/(questions/.*) http://example2.com/$1 [R=301,L,NC,NE] 
+0

我仍然有這樣的問題:但是從'example.com /幫助/問題/顯示/ some_text'不起作用重定向 - 我有'example2.com/help/questions/show/some_text'而不是'example2.com/questions/show/some_text'。 'help'不是必需的 – Dev

+0

請確保將此規則作爲您的第一條規則並完全清除您的瀏覽器緩存。 – anubhava

+1

是的,也許緩存是錯誤的!謝謝 – Dev

0
  1. 確保您在httpd.conf或apache.conf中設置了「AllowOverride All」。
  2. 確保啓用了rewrite_module,headers_module和alias_module apache模塊。
相關問題