View Single Post
  #3 (permalink)  
Old 11-26-2008, 05:32 PM
a53mp a53mp is offline
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 139
a53mp RepRank 2
Default Re: Search engine friendly urls

Quote:
Originally Posted by wige View Post
Try:

RewriteRule ^/services/(.*)$ /services.php?id=$1 [L]

In the first portion of the rule, the question mark has a different meaning than it does in the second portion. In the first portion, it is used to denote the end of the URI. In the second portion, it denotes a variable. The text you want to store in a variable should be enclosed in parenthesis. In this case, I used .*, which is a regular expression. The dot matches any single character, while the asterisk matches any number of characters. If the only valid character is a single digit number, the following rule should work instead:

RewriteRule ^/services/[1-9]$ /services.php?id=$1 [L]

If the rule should work on any number, from one to four digits, you could use this:

RewriteRule ^/services/[0-9]{1,4}$ /services.php?id=$1 [L]
if you want to allow numbers and letters use

RewriteRule ^/services/[a-zA-Z0-9]$ /service
if you want to add other characters like a dash...

RewriteRule ^/services/[a-zA-Z0-9.-]$ /service
Reply With Quote