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
Php htaccess将非www子文件夹重写为www子文件夹重定向到www根目录_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php htaccess将非www子文件夹重写为www子文件夹重定向到www根目录

Php htaccess将非www子文件夹重写为www子文件夹重定向到www根目录,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我想重定向 mydomain.com/subfolder mydomain.com/subfolder 到 使用.htaccess 这就是我尝试过的 Root.htaccess: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .? http://www.%{HTTP_HOST}/{REQUEST_URI} [R=301,L]

我想重定向

mydomain.com/subfolder
mydomain.com/subfolder

使用.htaccess

这就是我尝试过的

Root.htaccess:

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

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%{HTTP_HOST}/{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(subfolder(?:/.*)?)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
因为一个奇怪的原因,它正在重定向

我尝试过只实现root.htaccess,只实现subfolder.htacess,包括root和subfolder.htacess,没有.htaccess重定向,只使用PHP重定向进行重定向。所有这些选项都会将mydomain.com/subfolder路由到www.mydomain.com

是否有其他东西正在重定向流量


谢谢

规则中似乎有一些语法错误。在根htaccess中尝试此操作,以重定向到
www
,包括子文件夹

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

看起来规则中有一些语法错误。在根htaccess中尝试此操作,以重定向到
www
,包括子文件夹

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