0

自分のドメインのすべての URL をリダイレクトしたい

domain.com/urls、www.domain.com/profile/user1.html などを subdomain.domain.com/urls および subdomain.domain.com/profile/user1.html などに変換します。

しかし、domain.comとwww.domain.comをsubdomain.domain.comにリダイレクトしたくありません

htaccess経由で可能ですか?

編集:内部ページとファイルのみをリダイレクトしたい。ただし、メインの domain.com はそのまま残します。

その他の例

domain.com/page1.html to subdomain.domain.com/page1.html

www.domain.com/members/admin.html to subdomain.domain.com/members/admin.html

www.domain.com to www.domain.com (no redirection here)
4

2 に答える 2

3

試す:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/.+
RewriteCond %{REQUEST_URI} !^/index\.(php|htm)
RewriteCond %{HTTP_HOST} !^subdomain.domain.com$ [NC]
RewriteRule ^ http://subdomain.domain.com%{REQUEST_URI} [L,R]

永続的にリダイレクトする場合は、角かっこを次のように変更します[L,R=301]

于 2013-04-22T22:05:48.100 に答える
0

最初に書き換えずにメイン ページを処理し、2 番目のルールで他のすべてをリダイレクトできます。

RewriteRule ^$ - [L]
RewriteCond %{HTTP_HOST} !^subdomain.domain.com$
RewriteRule ^.+$ http://subdomain.domain.com/$0 [R,L]

すべてが期待どおりに機能したら、 に変更できRますR=301

于 2013-04-22T22:22:33.957 に答える