0

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

2 Answers 2

3

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget to exclude any trailing slash, if present.
1

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.

1 Comment

mmh.. The regex i want to make is that must match a-z, A-Z, 0-9, underscores and dots.. and also if is present or not a final shash.. RewriteRule ^([\w\.]+)/?$ ?page=user&id=$1 [L] this may do the job? Thank you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.