Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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/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
Php .htaccess重定向代码重定向到自定义404找不到,而不是将www重定向到非www版本_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php .htaccess重定向代码重定向到自定义404找不到,而不是将www重定向到非www版本

Php .htaccess重定向代码重定向到自定义404找不到,而不是将www重定向到非www版本,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我正在使用这个重定向代码 # Redirect www urls to non-www RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.8mags\.com [NC] RewriteRule (.*) http://8mags.com/$1 [R=301,L] 这会将我重定向到我创建的自定义404页面。这是我从中得到的一些额外信息 我不明白最后一行是什么意思以及如何纠正问题?我对您的URL进行了快速测试http://www.8mags.com/

我正在使用这个重定向代码

# Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.8mags\.com [NC]
RewriteRule (.*) http://8mags.com/$1 [R=301,L] 
这会将我重定向到我创建的自定义404页面。这是我从中得到的一些额外信息


我不明白最后一行是什么意思以及如何纠正问题?

我对您的URL进行了快速测试
http://www.8mags.com/lessons/
并将其重定向到:
http://8mags.com/8mags/lessons/
而不是
http://8mags.com/lessons/
。这意味着您在
/8mags/
子目录中保留了上述规则,而不是
DocuemtnRoot

如果
/8mags/
是您的
文档根,则将上述规则移动到父目录

您还可以使用
%{REQUEST\u URI}
修复它:

# Redirect www urls to non-www
RewriteEngine on

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

您的htaccess中有其他规则吗?是的,我有其他代码,但它与gzip压缩有关。实际上,有两个域托管在同一个帐户上。.htaccess位于这两个的根目录下,我是说公共根目录下,我将编辑重定向代码并告知问题是否已解决。没有问题,请在新浏览器中测试或清除浏览器缓存。嘿,谢谢。你是对的,现在已经解决了。浏览器是否也能捕获.htaccess文件?没有浏览器不知道关于htaccess的任何信息,它只缓存重定向(301)谢谢您的澄清:D
# Redirect www urls to non-www
RewriteEngine on

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