Marco
Marco

Reputation: 2737

RewriteRule: How to make the second argument optional

I'm trying to create a rewrite rule, were the second argument MUST be optional. But, for some reason, i don't know how to make so:

RewriteRule ^galeria/place/country/(.*)/([0-9]+)/?$ gallery/geography.php?country=$1&p=$2 [L]

Considering one case for testing purposes, let's pick the country Argentina, this is all the possibilities:

http://www.mywebpage/galeria/place/country/argentina
http://www.mywebpage/galeria/place/country/argentina/
http://www.mywebpage/galeria/place/country/argentina/3
http://www.mywebpage/galeria/place/country/argentina/3/

Remember that the last argument, the page, is optional

I know i'm close but i can't figure out how to make the second argument, on the rewrite rule, optional. Help. Thanks

Upvotes: 1

Views: 31

Answers (1)

anubhava
anubhava

Reputation: 786091

You can use:

RewriteRule ^galeria/place/country/([^/]+)(?:/(\d+))?/?$ gallery/geography.php?country=$1&p=$2 [L,QSA]

Upvotes: 1

Related Questions