2

I am using this regular expression on my htaccess:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_-\s]+)/([A-Za-z0-9_-\s]+)/?$ index.php?param1=$1&param2=$2 [L,NC]

The problem is this works with any variation of this:

example.com/search/test product 123
example.com/search/test+product+123
example.com/search/testproduct123
example.com/search/test%20product%20123

But when I throw a period (.) into it it doesn't match and I get a 404 message. I'm a rookie to regular expression and cannot figure out the syntax to add to [A-Za-z0-9_-\s] to allow all characters. I believe [.*] would work but it still send me to a 404.I want to allow period in the rewrite rule with what I currently have.

Updated:

So how would I take this:

^([A-Za-z0-9_-\s]+)/([A-Za-z0-9_-\s]+)/?$

And allow it to recognize a string like this:

search/st.+charles
csteel
  • 373
  • 1
  • 6
  • 16

2 Answers2

4

To allow a dot (.) you have to escape it, so use \. instead of .. You can also use [^abc] to allow all characters but abc.

Edit:

To allow dots in the path, use this:

^([A-Za-z0-9_-\s\.]+)/([A-Za-z0-9_-\s\.]+)/?$

Community
  • 1
  • 1
martinczerwi
  • 2,837
  • 23
  • 23
  • I want to allow period in the rewrite rule with what I currently have. So how would I take this: ^([A-Za-z0-9_-\s]+)/([A-Za-z0-9_-\s]+)/?$ And allow it to recognize a string like this: search/st.+charles – csteel Aug 27 '12 at 16:16
0

RewriteRule ^([a-zA-Z0-9-]+)([/]*)$

bobbiloo
  • 422
  • 5
  • 22