【问题标题】:htaccess redirect root only without changing urlhtaccess 仅重定向根而不更改 url
【发布时间】:2015-04-03 09:18:47
【问题描述】:

我有 2 个网站:

www.test1.com

www.test2.com 

使用下面的代码,我可以从 test1.com 重定向到 test2.com 而无需更改 url

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test1.com
RewriteRule ^(.*) http://test2.com/$1 [P]

但如果我尝试访问 test1 中的文件夹,例如 test1.com/folder,它也会重定向。 那么我如何只能重定向根文件夹但仍然不更改 url 但能够访问我的主域中的子文件夹?

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

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

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

    【讨论】: