Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess:将站点域重定向到子域_Php_.htaccess_Redirect - Fatal编程技术网

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

Php htaccess:将站点域重定向到子域,php,.htaccess,redirect,Php,.htaccess,Redirect,我需要在.htaccess文件中将访问mysite.com的用户重定向到www.mysite.com 问题是我尝试的任何东西都不起作用,我认为这是因为^mysite.com不排除www.mysite.com,因此这将创建一个坏循环,但我通常会得到错误500 我还需要排除另一个子域,img.mysite.com 我该怎么做 我使用了网络中的许多示例&一些htaccess生成器,它们为我提供了以下代码: Options +FollowSymLinks RewriteEngine on Rewrite

我需要在.htaccess文件中将访问mysite.com的用户重定向到www.mysite.com

问题是我尝试的任何东西都不起作用,我认为这是因为
^mysite.com
不排除
www.mysite.com
,因此这将创建一个坏循环,但我通常会得到错误500

我还需要排除另一个子域,
img.mysite.com

我该怎么做

我使用了网络中的许多示例&一些htaccess生成器,它们为我提供了以下代码:

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

试着这样做:


重新启动发动机
重写cond%{HTTP_HOST}^www.mywebsite.com$[NC]
重写规则^/()$$1[L,R=301]


这是您所需要的-取自默认Drupal.htaccess

^example.com(请使用该域作为示例)不排除
www.example.com
,因为它以
^
开头锚定。。。而且它不会重写
img.example.com
。我会删除
[nc]
(前面应该有一个空格,但它不是必需的)
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]