ATLChris
ATLChris

Reputation: 3296

Rewrite Rule To Detect Numbers Only

I am trying to create a rewrite rule which will detect numbers only and forward them accordingly. I want the rewrite rule to be ignored if anything but numbers appears.

What I have so far:

RewriteEngine on
RewriteRule ^([0-9]+)?$ view.php?id=$1 [L]

Upvotes: 7

Views: 7427

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270609

Remove the ? from the end of the ([0-9]+) group, which makes it optional. You must have numbers for the rewrite to occur:

RewriteEngine on
RewriteRule ^([0-9]+)$ view.php?id=$1 [L]

Upvotes: 10

Related Questions