user13612328
user13612328

Reputation:

how do i allow space in regex in mod_rewrite engine

i have a regex that i want it to allow white spaces. this regex i am using is in the .htaccess file. whenever i put the \s it makes the whole regex not work

what can i do to make it allow white spaces and work?

this is my regex:

([a-zA-Z0-9_-]+)\/?$

RewriteRule ^(?!profile|home|recieved|search|ajaxsearch|sent|favorites|deletemessage|favorite|replypopup|deletereply|Editprofile|changepass|followingsystem|checkFollowers|block|report|logout|login|register|forgotpassword|resetpassword|twitterapi|index|manage)([a-zA-Z0-9_-]+)\/?$ ./searchusers.php?search=$1 [L]

this is my full rewrite rule, when i put \s it doesn't work

Upvotes: 1

Views: 38

Answers (1)

anubhava
anubhava

Reputation: 784878

Have your rule like this:

RewriteRule ^(?!profile|home|recieved|search|ajaxsearch|sent|favorites|deletemessage|favorite|replypopup|deletereply|Editprofile|changepass|followingsystem|checkFollowers|block|report|logout|login|register|forgotpassword|resetpassword|twitterapi|index|manage)([^/]+)/?$ ./searchusers.php?search=$1 [L,QSA,NC]

Here [^/] is negated character class that matches any character except / and it will match whitespace as well.

Upvotes: 1

Related Questions