使用htaccess删除了参数,但仍然具有clean和参数url


Removed parameters with htaccess but still have both clean and parameter urls

我在菜单中有一个url,如下所示:

http://www.example.com/index.php?main_page=contact_us

我正在使用.htaccess中的以下内容将其转换为"干净"url:

RewriteRule ^/?([^/d]+)/?$ index.php?main_page=$1 [L,QSA]

尽管这是有效的,就像在中一样,我可以使用毫无问题地访问联系人页面http://www.example.com/contact_us它实际上并没有将原始链接更改为那样。

所以现在我想我需要改变php菜单中的链接以使用干净的url,或者使用更好的htaccess重写规则来自动执行。我更喜欢后者,有什么想法吗?

您可以插入此新规则来执行此重定向:

RewriteCond %{THE_REQUEST} 's/+index'.php'?main_page=([^'s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
RewriteRule ^([^/.]+)/?$ index.php?main_page=$1 [L,QSA]