Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess htaccess将非www子文件夹重定向到www子文件夹_.htaccess_Subdirectory - Fatal编程技术网

.htaccess htaccess将非www子文件夹重定向到www子文件夹

.htaccess htaccess将非www子文件夹重定向到www子文件夹,.htaccess,subdirectory,.htaccess,Subdirectory,我想重定向 example.com/subfolder 到 使用htaccess 这是我尝试过的,但不起作用: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] 出于一个奇怪的原因,它正在重定向 example.com/subfolder 到 有人能帮我吗?试试看 RewriteCond %{HTTP_HOST} !^www\.

我想重定向

example.com/subfolder

使用htaccess

这是我尝试过的,但不起作用:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
出于一个奇怪的原因,它正在重定向

example.com/subfolder

有人能帮我吗?

试试看

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L]

用这个。它是通用的。它重写了一切。即使你有别名

#Rewrite for non www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

如果只想顶部重定向
子文件夹
,则URI匹配正则表达式应只匹配子文件夹。试试这个规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(subfolder(?:/.*)?)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]

我也有同样的问题。我已经尝试了子文件夹.htaccess文件、根目录.htaccess文件、子文件夹和根目录.htaccess文件中列出的所有这些摘录,没有.htaccess重定向,并使用php重定向,但它们都使我回到了网站的根目录。@ShoreShotWeb:用您的问题打开一个新问题,我将参加讨论。