Norman
Norman

Reputation: 6365

htaccess allow if page number is supplied or not supplied

Eg:

RewriteRule ^/?(us|uk)/(national|regional)/([a-z0-9]+)/?$ /fetch/index.php?country=$1&scope=$2&page=$3 [NC,L]

In the above rule, the last part ([a-z0-9]+) specifies the page number. The page number may be there or may not be there. In both cases, the rule should work. Is it possible to do this?

Right now, I have one rule for when a page number is supplied, and another for when it's not.

How can I write a single rule that'll get through when a page number is supplied and even when not?

So:

http://www.example.com/us/national/ -> allowed with no page number
http://www.example.com/us/national/pg3 -> allowed with page number 

Upvotes: 1

Views: 32

Answers (1)

Shadow Radiance
Shadow Radiance

Reputation: 1369

Change the + to a * in the last segment should do it

Upvotes: 1

Related Questions