简体   繁体   English

htaccess:将站点域重定向到子域

[英]htaccess: redirecting site domain to subdomain

I need to redirect users accessing mysite.com to www.mysite.com in my .htaccess file. 我需要将访问mysite.com的用户重定向到我的.htaccess文件中的www.mysite.com。

The problem is anything I try won't work, I think because ^mysite.com doesn't exclude www.mysite.com so that will create a bad loop, but I usually get error 500. 问题是我尝试的任何东西都不起作用,我认为因为^mysite.com不排除www.mysite.com所以会创建一个糟糕的循环,但我通常会得到错误500。

I also need to exclude another subdomain, the img.mysite.com . 我还需要排除另一个子域名img.mysite.com

How can I do that? 我怎样才能做到这一点?

I used many examples from the net & a few htaccess generators, which gave me this code: 我使用了很多网络和一些htaccess生成器的例子,它给了我这个代码:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com[nc]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]

尝试这样的事情:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^/ (. )$ http://www.mywebsite.com/ $1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This is what you need - taken from the default Drupal .htaccess 这就是您所需要的 - 取自默认的Drupal .htaccess

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

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