Fr0z3n
Fr0z3n

Reputation: 1576

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..

Upvotes: 0

Views: 63

Answers (2)

Scott Stevens
Scott Stevens

Reputation: 2651

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.

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324640

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]

Upvotes: 3

Related Questions