Simple one

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Simple one

Post by klevis miho »

What regex do I need for this rewrite rule:
domain.com/a-number

to domain.com/index.php?page=a-number

I did this one:
RewriteRule ([1-9]+) index.php?page=$1 [NC]

but was not good.

Any suggestions?
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Simple one

Post by klevis miho »

Never mind, I've got it:
RewriteRule ^([1-9]+)$ index.php?page=$1 [NC]
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Simple one

Post by ridgerunner »

Your regex doesn't allow for the numbers, 10, 20, etc since it doesn't include the digit zero. Try this one ...

[text]RewriteRule ^([1-9]\d*)$ index.php?page=$1 [NC][/text]
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Simple one

Post by klevis miho »

Thanks, but wouldn't this: ^\d+$
be better?
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Simple one

Post by ridgerunner »

Yes, if you wish to allow page zero.
Post Reply