user1411607
user1411607

Reputation:

Allow space in .htaccess url redirect

I have redirected url with special characters to 400 error page using .htaccess which is working fine.

I am redirecting this way.

RewriteCond %{QUERY_STRING} [^\w+=&/.()-] [OR]
RewriteCond %{REQUEST_URI} [^\w+=&/.()-]
RewriteRule .? /site/error/400/? [L,B,R]

I want to allow spaces in query too, I am trying this way but its not working.

RewriteCond %{QUERY_STRING} [^\w\s+=&/.()-] [OR]
RewriteCond %{QUERY_STRING} [^\w+=&/.()-\s] [OR]
RewriteCond %{QUERY_STRING} [^\w+=&/.()\s-] [OR]
RewriteCond %{QUERY_STRING} [^\w\d\s+=&/.()-] [OR]

Please see and suggest any possible way to do this.

Thanks.

Upvotes: 2

Views: 885

Answers (2)

anubhava
anubhava

Reputation: 784868

You can use %20 for space:

RewriteCond %{QUERY_STRING} [^\w=+&/.%20()-] [OR]
RewriteCond %{REQUEST_URI} [^\w+=&/.()-]
RewriteRule ^ /site/error/400/? [L,B,R]

Upvotes: 2

ôkio
ôkio

Reputation: 1790

Try this

RewriteCond %{QUERY_STRING} [^\w\s+=&/.() -]

Upvotes: 0

Related Questions