htaccess 重定向是否存在特定 URL 变量
我已经努力阅读了好几个小时了,但仍然找不到我需要的东西!希望这里有人可以提供帮助。
我想要实现的是将具有特定变量的特定 URL 重定向到另一个页面,但当存在其他 URL 变量时则不会。
例如。
- index.php?option=com_user - 需要重定向到index.php
- index.php?option=com_user&view=login - 不得重定向
- index.php?option=com_user&view=login&foo=bar -这不能被重定向
我已经找到了很多测试给定变量是否存在的示例,但我想测试该变量并测试是否不存在其他变量。
有人可以帮忙吗?
提前致谢。
I've been reading hard for a good few hours and still can't find what I need! Hopefully someone here can help.
What I want to achieve is to redirect a specific URL with a specific variable to another page, but not when there are other URL variables present.
eg.
- index.php?option=com_user - this needs to be redirected to index.php
- index.php?option=com_user&view=login - this must not be redirected
- index.php?option=com_user&view=login&foo=bar - this must not be redirected
I've found lots of examples that test for the existence of a given variable, but I want to test for that variable and test that no other variables exist.
Can anyone help?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以说,如果您只进行内部重定向,并且其他参数不存在,您的脚本可以忽略该参数。但是,这不是您所要求的,所以让我们看看如何使用
mod_rewrite
来完成此操作。如果我们只关心查询字符串中是否有其他内容,我们可以简单地检查
option=com_user
是否是唯一的内容:但是,这仍然允许
/index.php?option=com_user&complete=nonsense
来溜过去,所以如果我们想要更严格一些,我们可以这样做:Arguably, if you'll only be doing an internal redirection, your script can just ignore that parameter if other parameters are not present. But, that wasn't what you asked, so let's see how this can be done with
mod_rewrite
.If we just care about if there's anything else in the query string, we can simply check if
option=com_user
is the only thing there:However, this would still allow
/index.php?option=com_user&complete=nonsense
to slip through, so if we wanted to be a little more restrictive, we could do something like this: