当前我的.htaccess如下所示
RewriteCond %{QUERY_STRING} ^&
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^age
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^gender
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^languages
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^sites
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^sortOrder
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^status
RewriteRule ^$ - [R=404]
RewriteCond %{QUERY_STRING} ^tags
RewriteRule ^$ - [R=404]
目前这工作得很好,如果我访问一个URL与参数之一,它会给予我一个404页面,我想知道是否有一个更好的方式来写这一点。
是否可以将所有这些合并到一行中?
我试过这样写
RewriteCond %{QUERY_STRING} ^&
RewriteCond %{QUERY_STRING} ^age
RewriteCond %{QUERY_STRING} ^gender
RewriteCond %{QUERY_STRING} ^languages
RewriteCond %{QUERY_STRING} ^sites
RewriteCond %{QUERY_STRING} ^sortOrder
RewriteCond %{QUERY_STRING} ^status
RewriteCond %{QUERY_STRING} ^tags
RewriteRule ^$ - [R=404]
但这并不奏效,因为它只适用于顶部查询,而不适用于其余查询
1条答案
按热度按时间ivqmmu1c1#
我试过这样写
RewriteCond
指令(* conditions *)是隐式AND的,因此上述操作永远不会成功(即,不会出现404),因为查询字符串不能同时匹配所有这些字符串。除最后一个 * condition * 外,您需要在所有其他 * condition * 上使用
OR
标志。例如:但是,这可以通过使用regex * alternate * 进一步减少。例如,上面的内容与下面的内容相同,只使用一个 * condition *: