Expand my Community achievements bar.

SOLVED

not able to forbidden url

Avatar

Level 2

we have to forbidden certain url based on condition.
for example if url contains /us/en/xyz/
and doesnot have query param view=true we have to forbidden the url.

RewriteCond %{QUERY_STRING} !view=true
RewriteCond %{REQUEST_URI} ^.*/us/en/xyz/.*
RewriteRule .* - [F]

but this is not working.
Can you please suggest the solution for this.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I have tested the same configuration on my local dispatcher, and it's working as intended. If you want to make the URL matching case-insensitive, be sure to add [NC] after the RewriteCond rules. Also, confirm that the URL is a child of /us/en/xyz/ and not the /us/en/xyz.html itself. 

RewriteCond %{QUERY_STRING} !view=true [NC]
RewriteCond %{REQUEST_URI} ^.*/us/en/xyz/.* [NC]
RewriteRule .* - [F]

Additionally, remember that the order of RewriteRules is crucial. Ensure that there are no prior rewrite rules that might be executed before this one, potentially affecting its behavior. If you could share the URL you've tried, we can provide more specific assistance.

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

I have tested the same configuration on my local dispatcher, and it's working as intended. If you want to make the URL matching case-insensitive, be sure to add [NC] after the RewriteCond rules. Also, confirm that the URL is a child of /us/en/xyz/ and not the /us/en/xyz.html itself. 

RewriteCond %{QUERY_STRING} !view=true [NC]
RewriteCond %{REQUEST_URI} ^.*/us/en/xyz/.* [NC]
RewriteRule .* - [F]

Additionally, remember that the order of RewriteRules is crucial. Ensure that there are no prior rewrite rules that might be executed before this one, potentially affecting its behavior. If you could share the URL you've tried, we can provide more specific assistance.

 

 

Avatar

Community Advisor

Hi @Sudarshan1992 
Rules are fine, you check here https://technicalseo.com/tools/htaccess/?share=ewogICJodGFjY2VzcyI6ICJSZXdyaXRlQ29uZCAle1FVRVJZX1NUU...

 

As mentioned by @Mahedi_Sabuj , there could be the other rules which are conflicting.



Arun Patidar