Lucas
Lucas

Reputation: 2984

htaccess - How to allow negative numbers in mod-rewrite?

In htaccess file I have that line:

RewriteRule ^something,([0-9]+)\.html$ something.php?num=$1 [L]

And if I open page with any number like something,7.html then everything works perfect, but how can I change rewrite rule if I want use a negative numbers as well, for example something,-2.html. Also I don't want to allow use letters.

Upvotes: 0

Views: 520

Answers (2)

Linus Kleen
Linus Kleen

Reputation: 34632

Adjust your regular expression to check for an optional "minus":

^something,(-?[0-9]+)\.html$

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143886

You want to add a \-? inside your match selection:

RewriteRule ^something,(\-?[0-9]+)\.html$ something.php?num=$1 [L]

Upvotes: 0

Related Questions