Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache .htaccess子域重定向规则_Apache_.htaccess - Fatal编程技术网

Apache .htaccess子域重定向规则

Apache .htaccess子域重定向规则,apache,.htaccess,Apache,.htaccess,我的网站有很多子域(第三级和第四级),例如: http://de.site.com/catalog http://product.de.site.com 例如,我需要用“www”自动重定向所有域 http://www.de.site.com/catalog http://www.product.de.site.com 要删除不带“www”的url: 你能帮我了解一下这个案子的访问规则吗?请注意,此规则只能应用于第三级以上的域。将此代码放入您的文档\u ROOT/.htaccess文件: Re

我的网站有很多子域(第三级和第四级),例如:

http://de.site.com/catalog
http://product.de.site.com
例如,我需要用“www”自动重定向所有域

http://www.de.site.com/catalog
http://www.product.de.site.com
要删除不带“www”的url:


你能帮我了解一下这个案子的访问规则吗?请注意,此规则只能应用于第三级以上的域。

将此代码放入您的
文档\u ROOT/.htaccess
文件:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

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

谢谢,它适用于所有级别的域。但是我需要用“www”-RewriteCond%{HTTP_HOST}^example.com$[NC]RewriteRule^(.*)$[R=301,L]来保存我以前的2rd级域规则。现在,它在2rd级域中运行良好,但在3+级域中仍然可以访问“www”,例如www.de.examle.com非常感谢!这正是我需要的!
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

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