How to redirect site to 403 if a certain url get variable exists or contains an unwanted value using htaccess

╄→尐↘猪︶ㄣ 提交于 2020-01-06 04:19:06

问题


In my site statistics, I'm staring to get strange URLs like these:

mysite.com/?p=casino-online-spielen

mysite.com/category/page/2/?p=casino-online-spielen

I've tried rewrites but it has messed up my WordPress rewrites or just didn't work. I am not that good in htaccess or apache.

<IfModule mod_alias.c>
RedirectMatch 403 ?p=(casino|pharmacy)
</IfModule>

What I need is a htaccess rule that sends the user to 403 error if the word casino is found, or better yet if ?p= is found in the URL, which is not supposed to happen. But I fear it will destroy archive pagination.

On the other hand, it should allows ?s= variables and whatever is in it.


回答1:


Essentially follow @Starkeen suggestion and use mod_rewrite eg.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{QUERY_STRING} p=(casino|pharmacy) 
  RewriteRule .* - [F,L]
</IfModule>

Note:

  • F = Forbidden = 403
  • L = Last = Just doooooo IT.


来源:https://stackoverflow.com/questions/32036831/how-to-redirect-site-to-403-if-a-certain-url-get-variable-exists-or-contains-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!