2011-08-25 86 views
0

好了,所以我在Opencart的應用程序中有這個網址,並運作良好爲什麼我的htaccess規則不是重寫URL

http://site.com/index.php?route=information/contact 

但客戶不喜歡的網址,並希望

http://site.com/contact 

我想通我可以做到這一點在我的htaccess以及一切都會好的,但訪問URL我得到什麼

RewriteRule ^(contact)$ index.php?route=information/contact [L,QSA] 

任何我DEAS

這裏是我的htacess

RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

RewriteRule ^contact$ /index.php?route=information/contact [L,QSA] 
+0

當您訪問http://site.com/contact會發生什麼?一個404? – ErJab

+0

如果是這樣,請檢查你的Apache的錯誤日誌。它會告訴你它到底是什麼試圖尋找並不能找到.. – ErJab

+0

是顯示一個404頁, – Trace

回答

5

刪除括號

RewriteRule ^contact$ index.php?route=information/contact [L,QSA] 

你的.htaccess應該是這樣的:

RewriteEngine On 
RewriteBase/
RewriteRule ^contact$ /index.php?route=information/contact [L,QSA] 
RewriteCond %{REQUEST_URI} !^/contact$ 
RewriteRule ^([^?]*) index.php?route=$1 [L,QSA] 
+0

奇怪...但仍沒有 – Trace

+0

這就是我對我的服務器做,你就把:RewriteEngine敘述在這個規則的權利過嗎?你之前有什麼規則? –

+0

您需要:RewriteEngine敘述在之前RewriteBase/ –

1

嘗試添加/ index.php的前

RewriteRule ^contact$ /index.php?route=information/contact [L,QSA] 
+0

我看到問題了RewriteRule ^([^?] *)index.php?_route _ = $ 1 [L, QSA] 正在引發問題...有沒有辦法做到這一點,除了聯繫 – Trace

2

是否啓用了mod_rewrite?此外,您可能有你的RewriteRules之前添加

RewriteEngine on

2

[OpenCart] Enable URL Rewriting for SEO

  1. 登錄到管理控制面板
  2. 選擇管理>配置>設置>服務器
  3. 選擇「SEO網址」選項是。
  4. 你完成了。
+0

我有一個衝突的規則RewriteRule ^([^?] *)index.php?_route _ = $ 1 [L,QSA]我可以有這個規則,但添加一個除了聯繫所以另一個規則可以工作 – Trace

+0

這個衝突的規則搞亂了一切,我已經更新了答案,你可以嘗試新的解決方案嗎? –