Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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
Regex .HTACCESS不将任何子域重定向到WWW,并保留其余子域_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex .HTACCESS不将任何子域重定向到WWW,并保留其余子域

Regex .HTACCESS不将任何子域重定向到WWW,并保留其余子域,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我已经为此做了很多搜索,但我还没有找到答案 我希望: 1仅将空白子域重定向到WWW。在示例中: http://website.com --> http://www.website.com 但是 2我不需要重定向http://*.website.com,因为我正在为许多子域使用通配符子域 任何帮助都将不胜感激。通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_根目录下的.htaccess中: Options +FollowSymLin

我已经为此做了很多搜索,但我还没有找到答案

我希望:

1仅将空白子域重定向到WWW。在示例中:

http://website.com --> http://www.website.com
但是

2我不需要重定向http://*.website.com,因为我正在为许多子域使用通配符子域


任何帮助都将不胜感激。

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_根目录下的.htaccess中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

完美的谢谢。如果这个答案帮助你解决了问题,请考虑将它标记为接受,所以将来面对类似问题的用户将能够轻松地看到它。