RewriteRule 末尾的问号 [英] Question mark in the end of RewriteRule

查看:28
本文介绍了RewriteRule 末尾的问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RewriteCond %{QUERY_STRING}  ^id=(.*)$
RewriteRule ^oldpage.php$ http://new-site.com/newpage-%1 [R=301,L]
and
RewriteRule ^oldpage.php$ http://new-site.com/newpage-%1? [R=301,L]

第一种情况的结果是
new-site.com/newpage-3?id=3
第二个
new-site.com/newpage-3

In first case result is
new-site.com/newpage-3?id=3
in second
new-site.com/newpage-3

第二次重写规则中的问号是什么意思?

What does question mark in second rewrite rule means?

推荐答案

?在目的地的末尾(目的地不是正则表达式)表示不带查询字符串前往该目的地.

The ? at the end of a destination (destinations are not regular expressions) means to go to that destination with no query string.

RewriteCond %{QUERY_STRING}  ^id=(.*)$
RewriteRule ^oldpage.php$ http://new-site.com/newpage-%1 [R=301,L]

如果查询字符串只包含一个 id,它会存储然后在目标中使用的值,所以如果你有

If the query string contains only an id, it stores the value which is then used in the destination, so if you have

http://foo.com/oldpage.php?id=54

你会得到

http://new-site.com/newpage-54?id=54

如果你有

RewriteCond %{QUERY_STRING}  ^id=(.*)$
RewriteRule ^oldpage.php$ http://new-site.com/newpage-%1? [R=301,L]

您将前往相同的目的地,但查询字符串为空,因此前往

You'll go to the same destination but with an empty query string, so going to

http://foo.com/oldpage.php?id=54

最终会在

http://new-site.com/newpage-54

这篇关于RewriteRule 末尾的问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆