如何编写我的重写规则,这样我就可以拥有友好的 url

How to write my rewriterule so I can have friendly url

我的 SEO 专家让我在 Opencart 安装中将 HTTP 301 重定向到一个友好的 URL。这个 Opencart 安装使用 SEO url 所以我有这个 url(opencart 中的原生 url): http://www.qcbikeshop.com/index.php?route=information/information&information_id=9

SEO url 是: http://www.qcbikeshop.com/Livraison-Gratuite

但是,我的 SEO 专家要我做一个 HTTP 301 重定向,这样当有人访问本机 URL(第一个)时,他会被重定向到 SEO url。

当我尝试在 .htaccess 中执行此操作时,Apache 说它处于无限循环中,我理解它。但是我没有找到如何实现我想要做的事情。

这是我当前在 .htaccess 文件中重写的内容:

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_= [L,QSA]

RewriteCond %{HTTP_HOST} ^qcbikeshop\.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www\.qcbikeshop\.ca$
RewriteRule ^/?$ "http\:\/\/qcbikeshop\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^qcbike\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.qcbike\.com$
RewriteRule ^/?$ "http\:\/\/qcbikeshop\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^qcbike\.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www\.qcbike\.ca$
RewriteRule ^/?$ "http\:\/\/qcbikeshop\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^spherikbike\.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www\.spherikbike\.ca$
RewriteRule ^/?$ "http\:\/\/www\.spherikbike\.com\/" [R=301,L]

Redirect 301 /mtb-comp-fr.html http://www.qcbikeshop.com/accessoires/pompes-velo/mtb-comp-fr.html

CPanel 重写工具为我上面的例子生成这个:

RewriteCond %{HTTP_HOST} ^qcbikeshop\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.qcbikeshop\.com$
RewriteRule ^index\.php$ "http\:\/\/www\.qcbikeshop\.com\/Livraison\-Gratuite" [R=301,L]

我觉得很不对。 感谢您的帮助!

您可以将此规则放在其他规则之上,看看它对您有何作用。

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?information/information&information=9
RewriteRule .* /Livraison-Gratuite? [R=301,L]