非 www .htaccess 重定向 - 忽略其他子域
我有一个“非 www”的 .htaccess 重定向,如下所示:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
它正在工作。但是,除了 www 之外,我还有一些子域。 例如,如果我调用 http://shop.example.com ,它会将我重定向到: http://www.shop.example.com
我不想将子域写入 .htaccess 文件,它应该自动工作,只需忽略除 www 和 '' 以外的任何内容,如下所示:
if subdomain =='' -> redirect to www.HTTP_HOST....
elseif subdomain !='' && subdomain !='www' -> do nothing.
谢谢!
I have a .htaccess redirect for "non www" like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
it is working. But, i have also some subdomains other than www.
If I call for example http://shop.example.com it redirects me to:
http://www.shop.example.com
I dont want to write the subdomains into the .htaccess file, it should work automatically, just ignore anything else than www and '' like this:
if subdomain =='' -> redirect to www.HTTP_HOST....
elseif subdomain !='' && subdomain !='www' -> do nothing.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这个规则:
并且还要考虑 HTTPS:
Try this rule:
And to also take HTTPS into account:
试试这个:
刚刚尝试过 internetagentur.drupal-webmaster.de (子域) - 主要是没有www。
try this:
Just tried it with internetagentur.drupal-webmaster.de (the subdomain) - the main is without www.
如果你想要一个 php 解决方案,你可以使用类似的东西:
这也会重定向到最初请求的页面。
If you want a php solution you could use something similar to this:
This would also redirect to the originally requested page.