Welcome to WebmasterWorld Guest from 54.167.29.254

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Matching a Keywords Component of a URI

Regular expression help to match a keywords part of a URI

     
10:47 pm on Mar 2, 2009 (gmt 0)

New User

5+ Year Member

joined:June 11, 2008
posts: 15
votes: 0


I have a web site that allows users to search for items matching keywords. I'd like the acceptable characters in the keywords to be as broad as possible and want to be able to rewrite URLS as follows:

[us-camera.gear-online-shop.com...]

to:

[us-camera.gear-online-shop.com...]

Where the plus in the keywords is a URL encoded space. i.e. Search for all camera gear matching "Series 6.0"

I am having trouble getting a regular expression matching the . (dot). At the moment I can match "Series+60" but not "Series+6.0".

Here is the rewrite rule I have at the moment:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦/[^.]*)$ [NC]
RewriteRule ^([0-9A-Za-z\.\s_\+\¦\:=\^\'\(\)\*`~;\-]*)$ index.php?keywordsText=$1

I would be very grateful if anyone can help.

11:11 pm on Mar 2, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


I don't think you need to 'escape' the dot in the list in [square] brackets, nor some of the other characters.

Note too, that

¦\.htm¦\.html¦
can be coded as
¦\.html?¦
for efficiency.
11:57 pm on Mar 2, 2009 (gmt 0)

New User

5+ Year Member

joined:June 11, 2008
posts:15
votes: 0


Thanks g1smd for your help. I've tried to simplify the expression to get the dot matching working. The following still won't match "Series6.0" but does match "Series60":

RewriteRule ^([0-9A-Za-z.]*)$ index.php?keywordsText=$1

Neither does:

RewriteRule ^([0-9A-Za-z\.]*)$ index.php?keywordsText=$1

1:51 am on Mar 3, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


The preceding RewriteCond specifically disables the rule if the URL contains a period...

RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦[b]/[^.]*[/b])$ [NC]

Jim
2:38 am on Mar 3, 2009 (gmt 0)

New User

5+ Year Member

joined:June 11, 2008
posts:15
votes: 0


Thanks - that was the answer.