简体   繁体   English

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

[英]mod_rewrite: change a single query string parameters

I have a URL like this: 我有这样的网址:

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

Now I have to find misspelled URLs with mod_rewrite like this: 现在,我必须使用mod_rewrite查找这样的拼写错误的URL:

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

unfortunally so far I wasn't able to find the correct RewriteRule : 不幸的是,到目前为止,我无法找到正确的RewriteRule

Options -MultiViews
RewriteEngine On

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

The problem seems to be the "?" 问题似乎是“?” which should mean QSD. 这应该表示QSD。 Anyway it was suggested this way in articles eg mod_rewrite to change query string parameter name 无论如何,在文章(例如mod_rewrite )中建议以这种方式更改查询字符串参数名称

So, how can I reorganize the query string values with mod_rewrite only? 那么,如何仅使用mod_rewrite重新组织查询字符串值? SEO-friendliness and hacking the PHP code is not an issue here SEO友好和破解PHP代码在这里不是问题

Try this rule: 尝试以下规则:

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

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

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