Adamski
Adamski

Reputation: 6019

regular expressions, modrewrite php apache

can any one see the problem with this?

the url is this normally:

page_test.php?page=latest_news&id=10518271191304876236

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

many thanks

Upvotes: 0

Views: 107

Answers (3)

Paolo Stefan
Paolo Stefan

Reputation: 10253

latest_news is not matched by [a-zA-Z0-9] because of the underscore _: you could use the word character class \w, which includes the underscore:

RewriteRule ^(\w+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

If the id is always numeric, you could shorten it even more using the number character class \d:

RewriteRule ^(\w+)/(\d+)$ page_test.php?page=$1&id=$2

Upvotes: 1

CristiC
CristiC

Reputation: 22698

RewriteRule ^([a-zA-Z0-9_]*)/([0-9]+)$ page_test.php?page=$1&id=$2

and you should be calling from:

www.yourdomain.com/latest_news/10518271191304876236

Upvotes: 1

Marc B
Marc B

Reputation: 360572

There's no / in your URL, and your pattern is requiring one:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2
                           ^---here

basically you're searching for:

one-or-more alpha-numerics separated by a / followed by one-or-more alphanumerics.

Upvotes: 2

Related Questions