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
Regex Apache非www到www错误地在URL上重写数组_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex Apache非www到www错误地在URL上重写数组

Regex Apache非www到www错误地在URL上重写数组,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我们有以下.htaccess配置: RewriteEngine on allow from all # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f # otherwise forward it to index.php RewriteRule . index.php RewriteCond %{HTTP_HOST} ^domain1\.domain2\.com$ [

我们有以下
.htaccess
配置:

RewriteEngine on
allow from all

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f

# otherwise forward it to index.php
RewriteRule . index.php

RewriteCond %{HTTP_HOST} ^domain1\.domain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain1\.domain2\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.domain1\.com\/$1" [R=301,L]

RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^/?$ "http\:\/\/www\.domain1\.com\/" [R=301,L]
除此之外,我们希望将所有非www URL重定向到带有www的URL

除了URL如下所示的页面外,其他页面都工作正常:

index?Form%5bplace%5d=Caribbean&Form%5bdestination%5d=Virgin+Islands&Form%5btype%5d=A
当我们输入不带www的URL时,我们的重定向将以以下URL结束:

index?Form%255bplace%255d=Caribbean&Form%255bdestination%255d=Virgin+Islands&Form%255btype%255d=A
这会导致404错误,因为无法识别


您知道如何避免这种情况吗?

用以下代码替换您的代码:

allow from all
Options +FollowSymLinks -MultiViews

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# if a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
# otherwise forward it to index.php
RewriteRule . index.php [L]

RewriteCond %{HTTP_HOST} ^domain1\.domain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain1\.domain2\.com$
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^domain1\.com$
RewriteRule ^/?$ http://www.domain1.com/ [R=301,L]

发生的情况是,
%
符号正在转义到
%25


Hi,它仍然在另一个浏览器中使用它转换为%255dTry。Hi,在chrome和safari中不起作用。但在firefox中,它工作得很好。这是在我实现您建议的代码之前发生的。为什么它在每个浏览器中的工作方式不同?清除每个浏览器的缓存。您好,它仍在转换为%255dHi,URL是我添加了这个重写条件%{HTTP\u HOST}^domain1.com$RewriteRule^/?$“HTTP\:\/\/www\.domain1\.com\/”[R=301,L,NE]