.htaccess 根域需要 www,子域不需要 www
我想设置如下所示的域:
example.com -> www.example.com
example.com/page -> www.example.com/page
www.example.com ->不重定向
www.example.com/page ->不重定向
subdomain.example.com ->不重定向
subdomain.example.com/page ->不重定向
www.subdomain.example.com -> subdomain.example.com
www.subdomain.example.com/page -> subdomain.example.com/page
http 和 https 也应该有效。
我从 .htaccess 需要 WWW 域,但允许子域(如果存在且没有硬编码)
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
它可以很好地工作于所有人,但除了下面:
www.subdomain.example.com -> www.subdomain.example.com
www.subdomain.example.com/page -> www.subdomain.example.com/page
子域不应包含“www”。前缀,但仍然带有“www”。前缀。
感谢您的教程。
i want set the domain like below:
example.com -> www.example.com
example.com/page -> www.example.com/page
www.example.com -> does not redirect
www.example.com/page -> does not redirect
subdomain.example.com -> does not redirect
subdomain.example.com/page -> does not redirect
www.subdomain.example.com -> subdomain.example.com
www.subdomain.example.com/page -> subdomain.example.com/page
http and https also should work.
I get the code from .htaccess to require WWW for domain, but allow subdomain if existing with no hard coding
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
it can work very well for all, but except below:
www.subdomain.example.com -> www.subdomain.example.com
www.subdomain.example.com/page -> www.subdomain.example.com/page
the subdomain should not have 'www.' prefix but it still with 'www.' prefix.
thanks for tutorial.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你拥有的规则之后添加这个
我还没有测试过,但我很确定我的理论是可靠的。至少假设示例中的 HTTPS 部分有效。
Add this after the rules you have
I haven't tested it out, but I'm pretty sure my theory's solid on it. At least assuming the HTTPS part from your example works.