我需要将主页重定向到一个域,将其余页面重定向到另一个域

I need to redirect homepage to one domain and rest of the pages to another domain

我需要将我的域 www.example.com 重定向到 www.new-example.com,但前提是用户请求根目录。如果它是子页面,那么我需要它转到子域。

示例:www.example.com/ -> www.new-example.com/ www.example.com/p1.html -> example.new-示例.com/p1

谢谢。

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此代码:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^/?$ http://www.new-example.com/ [L,R=302]

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ http://example.new-example.com/ [L,R=302,NE]