简体   繁体   English

.htaccess带有参数的重写规则

[英].htaccess rewrite rule with parameters

I have a lot of urls in the following format. 我有许多以下格式的网址。

index.php?option=com_letflat&task=view&id=42

index.php?option=com_letflat&task=view&task=ajaxmap

I want to rewrite all urls that contain option=com_letflat to the root of the domain, ie http://www.example.com 我想将包含option = com_letflat的所有URL重写为域的根,即http://www.example.com

I have tried dozens of different things, and none seem to work. 我尝试了数十种不同的方法,但似乎都没有效果。 I have got as far as this: 我到目前为止:

RewriteCond %{QUERY_STRING} (^|&)option=com_letflat [NC]
RewriteRule ^index.php(.*)  http://www.example.com [R=301,L]

But it doesn't work. 但这是行不通的。

Thanks 谢谢

You can use this rule: 您可以使用以下规则:

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)option=com_letflat(&|$) [NC]
RewriteRule ^index\.php /? [R=301,L]

Just make sure this is very first rule in your .htaccess 只要确保这是您的.htaccess中的第一条规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM