首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >url重定向精确匹配(包括参数)

url重定向精确匹配(包括参数)
EN

Stack Overflow用户
提问于 2015-04-29 07:26:00
回答 1查看 1.5K关注 0票数 1

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

示例:

代码语言:javascript
运行
复制
/en-direct.php?page=7

去:

代码语言:javascript
运行
复制
http://www.example.org/news/

和页:

代码语言:javascript
运行
复制
/en-direct.php?page=8

去:

代码语言:javascript
运行
复制
http://www.example.org/awesome-but-totally-different-page/

我用:

代码语言:javascript
运行
复制
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/

但是:我每次都从重定向页面(示例- http://www.example.org/different-page?page=7 )获得所有参数的http://www.example.org/different-page?page=7

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-29 07:30:25

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

代码语言:javascript
运行
复制
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]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29936984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档