homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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)

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:




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)

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)

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)

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

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



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

Thanks - that was the answer.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved