使用htaccess重定向url和掩码域



我正在尝试做一个小调整,这样我就可以在一个主机中容纳两个域,但我缺少的是-无法屏蔽地址栏中的url。这就是我的意思:我有两个域-test1.com和test2.comtest1.com位于/(根)目录,test2内容位于/subdr/

我使用htaccess重定向301:将所有请求从test2.com重定向到/subdir/

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^test2.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.test2.com$
  RewriteRule (.*)$ http://test1.com/subdir/ [R=301,L]
</IfModule>

这很好,但我收到的地址是:http://test1.com/subdir/如何屏蔽/重写此地址url,使其显示为http://test2.com?

你能试试这个规则吗:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^(www.)?test2.com$ [NC]
  RewriteRule ^(index.php)?$ /test2.com/index.html [NC,L]
  RewriteCond %{REQUEST_URI} !.(css|js|jpe?g|gif|bmp|png|tiff|ico)$ [NC]
  RewriteCond %{HTTP_HOST} ^(www.)?test2.com$ [NC]
  RewriteRule !^(test2.com|stylesheets|js)/ /test2.com%{REQUEST_URI} [NC,L,NE]
</IfModule>

最新更新