Page 1 of 1

matching %20 character in the URIs

Posted: Fri Sep 22, 2006 6:35 am
by miro_igov
What regular expression i need to match the /hello%20world part in http://www.domain.com/hello%20world ?

Posted: Fri Sep 22, 2006 6:38 am
by n00b Saibot
basename() can do this trick for you easily i think...

Posted: Fri Sep 22, 2006 7:00 am
by miro_igov
Not in the case, i need to do the match in the .htaccess file within a mod rewrite rule. Also it is possible to have some much complex URI /somephpile.php?paramA=1&p2=regexp&p3=hello%20world, so i want to check if the URI contains %20, basename() is useles.

Posted: Fri Sep 22, 2006 11:34 am
by feyd
Can we ask why you want to do this in a mod_rewrite rule instead of PHP?

Posted: Fri Sep 22, 2006 12:54 pm
by miro_igov
Yes, because i have already made it possible to access member profiles in a community site just when you type the user name after the domain -
http://domain.com/username and RewriteRule /([a-z9-0_-])$ /profile.php?name=$1

But if the user name contains space for example domain.com/user name this looks like domain.com/user%20name and the above regexp patern cannot detect the % character.

What patern i need to match the space in the user name ?

Posted: Fri Sep 22, 2006 12:57 pm
by feyd

Code: Select all

RewriteRule /(.+)$ /profile.php?name=$1
possibly.

Posted: Fri Sep 22, 2006 2:38 pm
by miro_igov
feyd wrote:

Code: Select all

RewriteRule /(.+)$ /profile.php?name=$1
possibly.
That is not a solution, will cause internal server error because the rewrite rule will match on every request even the request after the rule (profile.php?name= alsow will triger redirection).

It should match exactly a-z A-Z 0-9 - _ %, which will allow opening URIs like file.php (the dot will not match) or subdirectories /subdir/, because the second slash also will not match.

But what should be the pattern ?

Posted: Fri Sep 22, 2006 2:54 pm
by feyd
You can add conditionals that check if the request points to an existing file/directory.

Posted: Fri Sep 22, 2006 2:59 pm
by Luke
you da man! I was going about it the wrong way... Now I am able to find whatever I need in the results... thanks man!