Home > Software engineering >  HTACCESS 403 : How to block url with a specific character
HTACCESS 403 : How to block url with a specific character

Time:12-02

I'm using wordpress and I have some duplicate url by spammer

https://www.mydomains.com/caterory/article-name/ ==> OK

https://www.mydomains.com/caterory/article-name/?vn/2022-06-24fivhg585.html ==> Wrong

I would like to block this kind of url with string ?vn/

I tried this but it's not working

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot) [NC]

RewriteCond %{QUERY_STRING} ^*vn/ [OR]

RewriteCond %{REQUEST_URI} ^*vn/

RewriteRule ^ - [F]

Any idea ? Many thanks !

CodePudding user response:

The following should work for you. Make sure to place it at the top or before your WP rewriterule block .

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot) [NC]

RewriteCond %{QUERY_STRING} ^vn/ [NC]
RewriteRule ^ - [F]

If you want to test this rule yourself , just comment out or remove the condition line RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot) [NC] and visit any URL starting with the querystring ?vn . You will get a 403 forbidden error.

CodePudding user response:

Many thanks for your advises and repply.

Unfortunately, it seems not working.

I placed it at the top on my WP rewriterule block and I removed the condition line RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot) [NC] But I have a 200 code.

Any idea ?

Many many thanks !

CodePudding user response:

OK I tried on a different environment and I words fine !

Because this page are not interesting I'm wondering if it's not better to get a 404 error for all.

RewriteEngine On RewriteCond %{QUERY_STRING} ^vn/ [NC] RewriteRule ^ - [R=404]

Any idea ?

  • Related