Reputation: 2296
I am using .htaccess to tunnel traffic to my index.php. Below is one of the lines I am using:
RewriteRule ^page/([0-9]*)$ /index.php?&page=$1
What I want is to allow only numeric values, and the word 'all'. So the regexp should match:
How can matching against both values be acchieved? A simple solution would be ([0-9al]*), but that isn't perfect as it also allows for values like 'al9', 'lalalala' etc. Thanks!
Upvotes: 1
Views: 232
Reputation: 5705
[0-9]*
also matches zero numbers, you have to use + instead of *
To add 'all', use the pipe:
RewriteRule ^page/([0-9]+|all)$ /index.php?&page=$1
disallow '0':
RewriteRule ^page/([1-9]{1}[0-9]*|all)$ /index.php?&page=$1
[1-9]{1}[0-9]*
means:
Upvotes: 3
Reputation: 784918
You can use:
RewriteRule ^page/((?!0+$)[0-9]+|all)/?$ /index.php?page=$1 [L,QSA,NC]
This will also avoid rewriting /page/0
/page/00
etc
Upvotes: 1