如何让浏览器在重写时显示干净的 URL?
我有一个看起来像这样的超链接:
http://domain.com/sample/comments/65
当我单击它时,它会变成这样:
http://domain.com/sample/comments/index.php?submissionid=65
我正在使用重写规则来使其执行此操作。这就是我想要的,除了我还希望浏览器中显示的 URL 仍然看起来像“http:// /domain.com/sample/comments/65。”
我该怎么做? .htaccess 文件显示如下。
RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ http://domain.com/sample/comments/index.php?submissionid=$1 [NC,L]
预先感谢,
约翰
I have a hyperlink that looks like this:
http://domain.com/sample/comments/65
And when I click on it, it goes to this:
http://domain.com/sample/comments/index.php?submissionid=65
I'm using a rewrite rule to make it do this. This is what I want, except I also want the URL displayed in the browser to still look like "http://domain.com/sample/comments/65."
How can I do this? The .htaccess file is displayed below.
RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ http://domain.com/sample/comments/index.php?submissionid=$1 [NC,L]
Thanks in advance,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须删除
http://domain.com/sample/
部分,否则它将强制重定向:B
标志也是必需的,因为您正在使用反向引用在查询字符串内,需要转义。手册说(强调我的):
如果您将重写规则放在虚拟主机或主配置中,只要请求主机与重写规则中的主机匹配,就不会出现这种情况。
You must remove the part
http://domain.com/sample/
, otherwise it will force a redirect:The
B
flag is also necessary because you're using the backreference inside a query string, which requires escaping.The manual says (emphasis mine):
This would not be case if you put the rewrite rule in the virtual host or main configuration as long the request host and the host in the rewrite rule matched.