Welcome to WebmasterWorld Guest from 50.19.53.104

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

     

dugald

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

5+ Year Member



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.

g1smd

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

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



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.

dugald

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

5+ Year Member



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

jdMorgan

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

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



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

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

Jim

dugald

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

5+ Year Member



Thanks - that was the answer.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month