2013-09-25 21 views
0

書面方式排列,我們有以下.htaccess配置:阿帕奇非WWW到www不好再對URL

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網址重定向到帶有www的人。

一切工作正常,除了網頁,網址是這樣的:

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錯誤。

任何想法如何避免這種情況?

回答

0

這種替換代碼:

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] 
+0

嗨,它仍然被轉換爲%255D – german

+0

嘗試使用其他瀏覽器。 – anubhava

+0

嗨,在鉻和Safari瀏覽器不起作用。但在Firefox中,它工作正常。這是在我實現你的建議代碼之前發生的。它在每個瀏覽器中的工作方式有多不同? – german

0

發生了什麼事是,%符號越來越逃到%25

You can avoid this using the NE flag on your rules

+0

嗨,它仍然被轉換爲%255d – german

+0

@GermanLiubitch你在瀏覽器欄中輸入什麼網址,它不起作用?另外,你的新的.htaccess的樣子是什麼? – ernie

+0

嗨,網址是http://ritzycharters.com/yacht/index?SearchForm%5Barea%5D=Caribbean&SearchForm%5Blocation%5D=Virgin+Islands我已經添加了這個RewriteCond%{HTTP_HOST}^domain1.com $ RewriteRule^/?$「http \:\/\/www \ .domain1 \ .com \ /」[R = 301,L,NE] – german