简体   繁体   English

htaccess - 允许某些参数,但如果是其他查询字符串,则重定向到404

[英]htaccess - allow certain parameters but redirect to 404 if other query string

Following problem: I have a form on a page and want to allow certain parameters to enable form value overwriting. 以下问题:我在页面上有一个表单,并希望允许某些参数启用表单值覆盖。 But if there is a questionmark in the url without any of the parameter I want to redirect to the 404 page. 但是如果url中有一个questionmark而没有任何参数我想重定向到404页面。

But my regex doesn't work very well... 但是我的正则表达式效果不好......

RewriteCond %{QUERY_STRING} !^(a=.*|b=.*|c=.*)
RewriteRule ^subfolder/(.*)$ - [R=404,L,NC]

But now my page only shows up if a parameter is set. 但现在我的页面只显示是否设置了参数。 http://example.com/subfolder/ does not work, but http://example.com/subfolder/?a=whatever works. http://example.com/subfolder/不起作用,但http://example.com/subfolder/?a=whatever是有效的。 I only want a redirect if there is a question mark without any my parameters. 如果有一个没有任何参数的问号,我只想要一个重定向。 How to do that? 怎么做?

You can use this rule: 您可以使用此规则:

RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(^|&)(a|b|c)= [NC]
RewriteRule ^subfolder/(.*)$ - [R=404,L,NC]

First condition RewriteCond %{QUERY_STRING} . 第一个条件RewriteCond %{QUERY_STRING} . makes sure that QUERY_STRING is non-empty. 确保QUERY_STRING非空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM