Why is my htaccess rule not rewriting the url

不想你离开。 提交于 2019-12-25 10:59:54

问题


Ok so i have this url in my opencart application and it works well

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

but the clients hates the url and wants

http://site.com/contact

i figured i could just do this in my htaccess and all would be good but visiting the url i get nothing

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

any ideas

here is my 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]

回答1:


remove the parenthesis

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

your .htaccess should look like:

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



回答2:


Is mod_rewrite enabled? Also, you might have to add

RewriteEngine on

before your RewriteRules




回答3:


[OpenCart] Enable URL Rewriting for SEO

  1. Login into Admin Control Panel
  2. Select Admin > Configuration > Settings > Server
  3. Select “SEO URL” option to yes.
  4. You are done.



回答4:


Try adding a / before index.php

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


来源:https://stackoverflow.com/questions/7184712/why-is-my-htaccess-rule-not-rewriting-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!