Apache htaccess仅重定向根目录而不更改url

Apache htaccess仅重定向根目录而不更改url,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我有两个网站: www.test1.com 及 使用下面的代码,我可以在不更改url的情况下从test1.com重定向到test2.com RewriteEngine On RewriteCond %{HTTP_HOST} ^test1.com RewriteRule ^(.*) http://test2.com/$1 [P] 但如果我尝试访问test1中的文件夹,例如test1.com/folder,它也会重定向。 那么,我如何只重定向根文件夹,但仍然不更改url,但能够访问我的主域中的子

我有两个网站:

www.test1.com

使用下面的代码,我可以在不更改url的情况下从test1.com重定向到test2.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test1.com
RewriteRule ^(.*) http://test2.com/$1 [P]
但如果我尝试访问test1中的文件夹,例如test1.com/folder,它也会重定向。
那么,我如何只重定向根文件夹,但仍然不更改url,但能够访问我的主域中的子文件夹?

只需更改您的正则表达式以仅允许登录页:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^test1\.com$ [NC]
RewriteRule ^/?$ http://test2.com [P]
RewriteEngine On

RewriteCond %{HTTP_HOST} ^test1\.com$ [NC]
RewriteRule ^/?$ http://test2.com [P]