codeGEN
codeGEN

Reputation: 714

htaccess regex mandatory number after a string

I have the following htaccess regex

RewriteRule ^sitemap_(set|art|sub)_(([0-9]+)?).xml$ index.php?url=sitemap&doc=$1&id=$2 [QSA,NE,L]

I need the "" sign followed by some number to be optional. And the "" sign alone cannot be present without having a number followed by that "_" sign.

I have tried to make the "_" sign to be optional by including a ? at the end but still strings like sitemap_set_ gets matched.

Hope my explanation is clear enough for you to help. else specify anything that looks confusing.

Upvotes: 1

Views: 89

Answers (1)

anubhava
anubhava

Reputation: 784918

You can use it like this:

RewriteRule ^sitemap_(set|art|sub)(?:_([0-9]+))?\.xml$ index.php?url=sitemap&doc=$1&id=$2 [QSA,NE,L]

This makes under followed by 1 or more digits optional.

Upvotes: 1

Related Questions