libertaire
libertaire

Reputation: 855

htaccess wildcard to match only numeric value

I use this:

RewriteRule ^(page-a[^/]+)/?$ /page.php?a=$1

the objective is to rewrite to pages like this:

http://www.website.com/page-a47643

now how can i match only strings containing NUMBERS following "page-a" ?

The problem is that the htaccess will mess up access to folder like this:

http://www.website.com/page-about-me/

Upvotes: 1

Views: 1438

Answers (4)

E. S.
E. S.

Reputation: 2919

RewriteRule ^page-a([0-9]+)/?$ /page.php?a=$1 [L,QSA]

Upvotes: 1

DimeCadmium
DimeCadmium

Reputation: 340

RewriteRule ^(page-a\d+)/?$ /page.php?a=$1

\d in Perl-compatible regular expressions (PCRE, as used by Apache) means "one digit". \d+ means "one or more digits".

Upvotes: 1

Tasos Bitsios
Tasos Bitsios

Reputation: 2789

RewriteRule ^(page-a[0-9]+)/?$ /page.php?a=$1

Upvotes: 1

anubhava
anubhava

Reputation: 784918

Change your regex to:

RewriteRule ^(page-a[0-9]+)/?$ /page.php?a=$1 [L,QSA]

[0-9]+ will match 1 or numbers and will leave /page-about-me/ as is.

Upvotes: 1

Related Questions