2012-12-12 168 views
0

編輯:我必須添加的東西。首先,我想改變URL顯示,因爲SEO。如果我使用WWW到達我的網站沒有問題,第二個鏈接出現,一切都OK。RewriteCond查詢字符串.htaccess

但是,如果我從鏈接中刪除「www」,它會更改爲第一個網址,我不希望這樣。

我想改變

​​

http://www.mysite.com/epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html

我該怎麼辦呢?

我試圖

RewriteCond %{QUERY_STRING} ^_route_=(.*)$ 
RewriteRule ^index\.php$ /%1 [R=301,L] 

,但它無法正常工作。

我的.htaccess是

RewriteBase/

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] 

RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

RewriteCond %{QUERY_STRING} ^route=common/home$ 
RewriteRule ^index\.php$ http://www.mysite.com? [R=301,L] 

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

回答

1

也許這是你在找什麼:

RewriteRule ^(.*)$ index.php?route=$1 [L] 

如果你有視覺上改變地址欄,離開重寫規則的地方,因爲我描述以上,並在任何輸出之前將其寫入index.php

if(isset($_REQUEST['route'])) 
{ 
    header('Location: '.urlencode($_REQUEST['route'])); 
} 
+0

謝謝,你打我去修復這個錯字;) – BenM

+0

當我添加內部服務器時發生錯誤。 :/ – codeGenius

+0

@BenM:任何時間...大聲笑 – cHao

0

首字記:我不是Apache大師,所以不要盲目依賴我的答案。

如果需要

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

然後讓它去在最後一行_route_查詢變量

# if it is the index page... 
RewriteCond %{REQUEST_URI} ^/(index\..+)?$ [NC] 
# and if the query string starts with _route_= 
RewriteCond %{QUERY_STRING} ^_route_=(.*)$ 
# redirect 
RewriteRule ^(.*)$ http://%{SERVER_NAME}/%1? [R=301,L] 

服務器變量SERVER_NAME指定的頁面可能需要我會首先重定向到www.改變與HTTP_HOST

+0

只要重定向到「我」,我實際上更喜歡將所有內容重定向到非「.www」域。 「www.'版本只是停留在周圍,因爲一羣人受過訓練,」網站地址以'www'開頭「。但我想引導人們遠離那種無意義的東西。 (不過,無論如何,這是一筆不小的交易;無論您是否重定向www,或者不重定向到哪個域,對於實際問題都無關緊要。) – cHao