2016-10-13 8 views
2

あるページを別のdomenにリダイレクトする必要があります。例: example.com/help/questions(/show/some_text|none|get params) Htaccess:1つのdomenから別のページにリダイレクトする

example2.com/questions(/show/some_text|none|get params)にhtaccessファイル:

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

しかしexample.com/help/questions/show/some_textからリダイレクトすることはできません - 私はいくつかの問題を抱えているようなコードでは代わりにexample2.com/help/questions/show/some_textexample2.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を持っています代わりに 'example2.com/questions/show/some_text'/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モジュールが有効になっていることを確認してください。
関連する問題