1

ドメイン old.test.ru と test.ru があります。すべてのページを old.test.ru/* から test.ru/* にリダイレクトするにはどうすればよいですか?

私はこれらの .htaccess を持っています:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /

   # redirect from index.(php|asp|aspx|html|htm), main.(php|asp|aspx|html|htm), home.(php|asp|aspx|html|htm)
   RewriteRule ^(.*)index\.(php|asp|aspx|html|htm)$ $1 [R=301,L]
   RewriteRule ^(.*)main\.(php|asp|aspx|html|htm)$ $1 [R=301,L]
   RewriteRule ^(.*)home\.(php|asp|aspx|html|htm)$ $1 [R=301,L]

   # redirect from dev and www
   RewriteCond %{HTTP_HOST} ^old\.test\.ru$ [OR]
   RewriteCond %{HTTP_HOST} ^www\.test\.ru$
   RewriteRule ^(.*)$ http://test\.ru/$1 [R=301,NC]
</IfModule>

最後の行だと思う

RewriteRule ^(.*)$ http://test\.ru/$1 [R=301,NC]

動作するはずですが、動作しません。

それはのために働く:

old.test.ru/about.php -> test.ru/about.php
old.test.ru/company.php -> test.ru/company.php
old.test.ru/contact.php -> test.ru/contact.php

しかし、うまくいきませんでした:

old.test.ru/some/about.php -> test.ru/some/about.php
old.test.ru/some1/company.php -> test.ru/some1/company.php
old.test.ru/some2/contact.php -> test.ru/some2/contact.php
old.test.ru/some2/subsome/contact.php -> test.ru/some2/subsome/contact.php

何を変更すればよいですか?

4

2 に答える 2

1

最後のルールを次のように置き換えてみてください。

 # redirect from dev and www
 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^ http://test.ru%{REQUEST_URI} [R=301,L]

更新:index.php URL から etcを削除するには:

 RewriteCond %{HTTP_HOST} ^(www|old)\.test\.ru$ [NC]
 RewriteRule ^(.*?)((?:index|default)\.(?:php|html?))?$ http://test.ru/$1 [R=301,L,NC]
于 2013-09-18T13:26:29.263 に答える
0

すべてのリクエストをリダイレクトする場合は、使用するのではなく、リダイレクトを使用します。old.test.rumod_rewrite

使用する構成でold.test.ruは:

Redirect permanent / http://test.ru/
于 2013-09-18T13:26:04.887 に答える