Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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/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 Apache未正确重定向“/usr/home/username/public\u html/”_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php Apache未正确重定向“/usr/home/username/public\u html/”

Php Apache未正确重定向“/usr/home/username/public\u html/”,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我用它将非www请求重定向到www RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 它应该从以下位置重定向: 致: 但它正在重定向到: http://www.example.com//usr/home/username/public_html/intranet 发生了什么以及如何解决此问题?我成功地使用了以下功能: RewriteBase /intrane

我用它将非www请求重定向到www

  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
它应该从以下位置重定向:

致:

但它正在重定向到:

http://www.example.com//usr/home/username/public_html/intranet

发生了什么以及如何解决此问题?

我成功地使用了以下功能:

RewriteBase /intranet/
RewriteCond %{HTTP_HOST}   !^www\. [NC]
RewriteRule ^(.*)          http://www.%{HTTP_HOST}/$1 [L,R]

你是把它放在虚拟主机配置中还是放在.htaccess中?我把它放在了一个.htaccess文件中,在一个子目录“intranet”中。这很奇怪。我有一些类似的方法来做相反的工作,但效果很好:RewriteCond%{HTTP_HOST}^www\..*$[NC]RewriteRule^.*$HTTP://%1/$1[R=301,L,QSA]添加RewriteBase/intranet/如果你的.htaccess在/intranet/@Cheery:为什么?它将更改传递到SAPI的请求字符串,以I/intranet为例,一个真实的站点可能有几十种不同的路径,您可以在根目录或子目录中使用?我在子目录中使用它。我只想提一下,它在本地测试了上述内容,并使用
http://www.example.com//usr/home/username/public_html/intranet
RewriteBase /intranet/
RewriteCond %{HTTP_HOST}   !^www\. [NC]
RewriteRule ^(.*)          http://www.%{HTTP_HOST}/$1 [L,R]