首页 文章

mod_rewrite:更改单个查询字符串参数

提问于
浏览
1

我有这样的网址:

http://foo.bar/index.php?page=this-is-the-page

现在我必须使用mod_rewrite找到拼写错误的URL,如下所示:

http://foo.bar/index.php?page=this--is-the-page

不幸的是到目前为止我无法找到正确的 RewriteRule

Options -MultiViews
RewriteEngine On

RewriteCond %{QUERY_STRING} ^page=(\w+)--((\w+)(-(\w+))*)$
RewriteRule ^index\.php$ /index.php?page=%1-%2

问题似乎是"?",这应该意味着QSD . 无论如何,有人在文章中提出这种方式,例如mod_rewrite to change query string parameter name

那么,如何仅使用mod_rewrite重新组织查询字符串值? SEO友好和黑客攻击PHP代码不是问题

1 回答

  • 0

    试试这条规则:

    RewriteCond %{QUERY_STRING} ^page=(.*?)--([^&]*)
    RewriteRule ^index\.php$ /index.php?page=%1-%2 [L,R]
    

相关问题