【发布时间】:2016-03-11 15:22:59
【问题描述】:
我试图在 apache 重写规则中省略 "?main_page=" 的 $_GET 变量的某些值。例如:
我有一些网址要重写,比如:
http://example.com/index.php?main_page=faq
http://example.com/index.php?main_page=login
http://example.com/index.php?main_page=contact_us
变成:
http://example.com/faq
http://example.com/login
http://example.com/contact_us
我能够做到这一点:
RewriteCond %{QUERY_STRING} main_page=(.*)
RewriteRule ^index\.php$ %1? [R=302,L]
不过,我也想从重写规则中省略某些“?main_page=”的值,例如:
http://example.com/index.php?main_page=index
http://example.com/index.php?main_page=page&id=2
http://example.com/index.php?main_page=advanced_search&search_in_description=1&keyword=cialis&inc_subcat=0
http://example.com/index.php?main_page=product_info&cPath=1&products_id=27
所以我尝试了类似的方法:
RewriteEngine on
Options -MultiViews
RewriteCond %{QUERY_STRING} main_page=(?!product_info)(?!page)(?!index)(?!advanced_search)
RewriteRule ^index\.php$ %1? [R=302,L]
但没有运气。我不擅长 regx 重写。我希望这是我犯的一个小错误。有人可以提供一些帮助吗?非常感谢。
【问题讨论】:
标签: regex apache .htaccess rewrite