matching %20 character in the URIs

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

matching %20 character in the URIs

Post by miro_igov »

What regular expression i need to match the /hello%20world part in http://www.domain.com/hello%20world ?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

basename() can do this trick for you easily i think...
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can we ask why you want to do this in a mod_rewrite rule instead of PHP?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

RewriteRule /(.+)$ /profile.php?name=$1
possibly.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can add conditionals that check if the request points to an existing file/directory.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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!
Post Reply