runkar
runkar

Reputation: 466

Url rewriting mod_rewrite

I'm using this tester for url mod_rewrite test: http://martinmelin.se/rewrite-rule-tester/

When I write something like this:

RewriteRule ^x/([a-z]+)/([0-9]+)/$ x.php?x=$2 

Even though I have entered url :

x/p/6/

It get renamed to

x.php?x=p 

and. What I want is

x.php?x=6

I'm new with mod rewrite, so anything would be useful.

Upvotes: 2

Views: 180

Answers (2)

Fad
Fad

Reputation: 9858

I'm not a pro in mod_rewrite myself, but I think there is something wrong with that tool. for example, if you change x.php?x=$2 to x.php?$1=$2, $2 will be parsed correctly. And then, CMIIW but the regex looks fine. Test the regex here or here. And Have you ever actually tried the RewriteRule yourself?

Upvotes: 2

ty812
ty812

Reputation: 3323

RewriteRule ^x/([a-z\/]+?)/([0-9]+)/$ x.php?x=$2 

This adds all / characters to the first regex block. The ? makes the search non-greedy.

Upvotes: 1

Related Questions