.htaccess url重定向精确匹配,包括参数

.htaccess url重定向精确匹配,包括参数,.htaccess,.htaccess,我想做一个301重定向,并从一个旧网站使用准确的url没有额外的参数 例如: /en-direct.php?page=7 转到: http://www.example.org/news/ http://www.example.org/awesome-but-totally-different-page/ 和第页: /en-direct.php?page=8 转到: http://www.example.org/news/ http://www.example.org/awesome-b

我想做一个301重定向,并从一个旧网站使用准确的url没有额外的参数

例如:

/en-direct.php?page=7
转到:

http://www.example.org/news/
http://www.example.org/awesome-but-totally-different-page/
和第页:

/en-direct.php?page=8
转到:

http://www.example.org/news/
http://www.example.org/awesome-but-totally-different-page/
我用过:

redirectMatch 301 ^/en-direct.php$ http://www.example.org/different-page/
redirectMatch 301 ^/en-direct.php?page=7$ http://www.example.org/news/
redirectMatch 301 ^/en-direct.php?page=8$ http://www.example.org/awesome-but-totally-different-page/
但是:我每次都从重定向页面获取所有参数(示例-)


任何帮助都将不胜感激

为了匹配查询字符串,您需要使用mod_rewrite:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^page=7($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/news/ [L,R=301]

RewriteCond %{QUERY_STRING} ^page=8($|&)
RewriteRule ^en-direct\.php$ http://www.example.org/awesome-but-totally-different-page/ [L,R=301]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^en-direct\.php$ http://www.example.org/different-page/ [L,R=301]

非常感谢。成功了。但是如何向重写条件添加多个参数?我会重写cond%{QUERY\u STRING}^page=7,另一个=8($|&)?@AryehArmon这正是查询字符串的样子,所以类似于:
RewriteCond%{QUERY\u STRING}^page=7,另一个=8$