2015-01-12 77 views
1

我在我的htaccess文件是什麼:htaccess的重寫規則增加了不必要的GET參數

RewriteEngine on 

# --- Remove index.php from URLs 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule .* index.php/$0 [PT,L] 
RewriteRule ^(.*)$ index.php?/$1 [L] 

RewriteRule ^city/([^/]+)/?$ /uk/city/$1 [R=301,L] 

我喜歡做的是重定向example.com/city/londonexample.com/uk/city/london

奇怪的是,它現在重定向到example.com/uk/city/london?city/london如此它似乎將它需要的部分作爲get參數重定向到新URL。

也試過Redirect 301 /city/london http://www.example.com/uk/city/london但這給出了相同的結果。

回答

0

你需要保持R=301(重定向)規則內部路由規則之前:

RewriteEngine on 

RewriteRule ^city/([^/]+)/?$ /uk/city/$1 [R=301,L] 

# --- Remove index.php from URLs 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule .* index.php/$0 [PT,L] 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

而且清除瀏覽器緩存,以測試這避免碰到老301緩存。

0

你可以嘗試這樣的事情,如果重定向301沒有工作:

RewriteRule /city/london uk/city/london [L] 

這裏是你的其他定義的.htaccess規則的一個例子:

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] 
RewriteRule /city/london uk/city/london [L] 

# --- Remove index.php from URLs 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteRule .* index.php/$0 [PT,L] 
RewriteRule ^(.*)$ index.php?/$1 [L]