Malasorte
Malasorte

Reputation: 1173

Make dynamic links (with ?) return error 404 not found

Using .htaccess (are there any other solutions?) is there a way to make all dynamic links (links containing the sign ?) of a site return a 404 not found response header?

For example:

http://www.example.com/?bla_bla - will return 404

http://www.example.com/test/index.html?no_redirect=true - will return 404

Upvotes: 0

Views: 271

Answers (1)

arco444
arco444

Reputation: 22821

I assume you're asking for any request containing a query string to return a 404. If that is what you want, use the below:

RewriteEngine On
RewriteCond %{QUERY_STRING} .+
RewriteRule .* - [R=404,L]

This will use the regex .+ to check if there are one or more characters in the query string. If that condition is met, any path (.* matches 0 or more characters) will be redirected as a 404

Upvotes: 1

Related Questions