2011-08-25 82 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

这个冲突的规则搞乱了一切,我已经更新了答案,你可以尝试新的解决方案吗? –