且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

htaccess的重定向存在一个特定的URL变量

更新时间:2022-12-09 11:06:39

可以说,如果你只是做一个内部重定向,你的脚本可以忽略该参数如果其他参数都没有present。但是,这是不是你问什么,让我们看看如何可以用的mod_rewrite 来完成。

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.

如果我们只关心是否有什么的其他查询字符串,我们可以简单地检查选项= com_user 是唯一有

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:

RewriteEngine On

RewriteCond %{QUERY_STRING} =option=com_user [NC]
RewriteRule index\.php index.php?

不过,这仍然让 /index.php?option=com_user&complete=nonsense 漏网之鱼,所以如果我们想一点更严格,我们可以做这样的事情:

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:

RewriteEngine On

# Check if the query string contains option=com_user
RewriteCond %{QUERY_STRING} (^|&)option=com_user(&|$)
# Check that all of these other parameters were not provided
RewriteCond %{QUERY_STRING} !(^|&)view=
RewriteCond %{QUERY_STRING} !(^|&)foo=
RewriteRule index\.php index.php?