针对这种情况进行 Mod 重写
我正在尝试重写 www.mysite.com/admin/index.php?page=pagename 到 www.mysite.com/admin/pagename
在我的 .htaccess 文件中(位于 www.mysite .com/admin)是以下代码行
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
但是,当我尝试访问时,
www.mysite.com/admin/mypage?querystring=value
我必须输入
www.mysite.com/admin/mypage&querystring=value
。第一个?必须是 &由于mod重写而签名。
我怎样才能制定一个重写规则来解决这个问题。所以我想
www.mysite.com/admin/mypage/?additional_query=value
重写为
www.mysite.com/admin/index.php?page=mypage&aditional_query=value
我认为谷歌使用#符号或其他东西,或者在后面放置一个/。我该怎么做?
Im trying to rewrite
www.mysite.com/admin/index.php?page=pagename to www.mysite.com/admin/pagename
In my .htaccess file (located in www.mysite.com/admin) is the following lines of code
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
However, when I try to access
www.mysite.com/admin/mypage?querystring=value
I have to type
www.mysite.com/admin/mypage&querystring=value
instead. The first ? must be an & sign because of the mod rewrite.
How can I make a rewrite rule that will fix this problem. So I want
www.mysite.com/admin/mypage/?additional_query=value
to rewrite to
www.mysite.com/admin/index.php?page=mypage&aditional_query=value
I think google uses the # sign or something, or places a / afterwards. How do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Apache 已经有一个简洁的小修饰符,您可以将其添加到 RewriteRule 的末尾。如果您只是将规则末尾的标志 (
[L]
) 更改为[QSA,L]
,它会将您的查询字符串附加到 URL 的末尾,而不是尝试重写仍然包含它的页面(只要查询字符串按预期以?
开头。我不确定,但我相信您需要删除
$
符号以及新行:
Apache already has a neat little modifier that you can add to the end of your RewriteRule. If you just change your flag (
[L]
) at the end of your rule to[QSA,L]
it will append your query string to the end of the URL, rather than trying to rewrite the page with it still included (as long as the query string starts with the?
as expected.I'm not sure, but I believe you need to remove the
$
symbol as well.New line: