Skip to content
Advertisement

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

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement