简体   繁体   English

htaccess仅重定向根域

[英]htaccess redirect only root domain

I would like to redirect my domain name from one site to another. 我想将我的域名从一个站点重定向到另一个站点。 I only want the rule to be applied if no other subpages are specified 我只希望在没有指定其他子页面的情况下应用规则

EG: 例如:

www.example.com 

would get redirected 会被重定向

www.example.com/folder/page.php

would not get redirected 不会被重定向

The code I have does a catch all and that is not what I want 我所拥有的代码可以捕获所有这些并不是我想要的

RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/folder/$1 [L,R=301]

You can use: 您可以使用:

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^/?$ http://newsite.com/folder/ [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM