Url Rewriting regex

I have this rule in my .htaccess

RewriteRule ^([^/\.]+)/?$ ?page=user&id=$1 [L]

It rewrite a url like

http://sitename.ext/nickname

to

http://sitename.ext/?page=user&nickname

The problem is that with a url with dots like http://sitename.ext/nick.name.test i get a 404 error..

I'm not good with regex..

Answers


That's because it's not being rewritten. You specificaly told it to exclude ., and that's what it's doing.

Personally, I would favour something like this:

RewriteRule user/(.+) ?page=user&id=$1 [L]

If you want to match any character except a slash, the regex is [^/], since the \. will cause it also to not match dots.

Your rule should be

RewriteRule ^([^/]+)/?$ ?page=user&id=$1 [L]

You might find this site helpful.


Need Your Help

unable to start the rails server

ruby-on-rails windows webrick

When I try to start my rails server i get this error

Excel 10 cell content validation dependant on another field

excel validation

I am trying to validate the entry in a cell based on the contents of another cell in the same workbook.