rahulkapoor99
rahulkapoor99

Reputation: 117

dot in htaccess gives 500 internal error

Options +Indexes
# or #
IndexIgnore *
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1 
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1

I want to add dot in rewrite rule so that the username with dot in between them works like rahul.kapoor doesn't works but rahulkapoor works , please help.

Upvotes: 2

Views: 365

Answers (2)

jeroen
jeroen

Reputation: 91742

Although the dot normally has a special meaning in a regex, it is not a metacharacter when used inside a character class, so in your case you could just use:

RewriteRule ^([a-zA-Z0-9_.-]+)/?$ profile.php?u=$1

Note that I have made the forward slash at the end optional so you only have to use one line instead of two.

Edit: You can also use the word metacharacter to simplify it further:

RewriteRule ^([\w.-]+)/?$ profile.php?u=$1

Upvotes: 2

Lix
Lix

Reputation: 47986

With regular expressions like the ones used in .htaccess files, the dot character has a special meaning. It means "(almost) any character".

If you want to use a "real" dot character, you'll have to escape it with a backslash:

RewriteRule ^([a-zA-Z0-9_-]+\.?[a-zA-Z0-9_-]*)/$ profile.php?u=$1

What I have done here is changed your regex rule to match:

  1. more than one alpha numeric character [a-zA-Z0-9_-]+
  2. an optional dot character \.?
  3. more (optional) alpha numeric characters [a-zA-Z0-9_-]*

Upvotes: 0

Related Questions