tags:

views:

149

answers:

4

I'm german and i'm sorry about my damn sucking englisch.

RewriteRule ^admin/(.*)$ index.php?admin=$1

here is an example. so the result i want is for example the id within, but as an optional parameter:

RewriteRule ^admin/(.*)/id-(.*)$ index.php?admin=$1&id=$2

Here the id don't must set thats what i want :)

The Link example (i want that here is the same result):

www.exmple.com/admin/edit-user
www.exmple.com/admin/edit-user/id-1

the problem is: the rule take anytime the first way with only this:

RewriteRule ^admin/(.*)$ index.php?admin=$1

can anybody help me ? :)

loving greetings m0.

+1  A: 

Try an optional capture group:

RewriteRule ^admin/([^/]*)(/id-(.*))?$ index.php?admin=$1&id=$3

If there's no id specified, then $3 will be blank and you'll just get a blank id rewritten:

index.php?admin=edit_user&id=

If it is specified, then you'll get the id too:

index.php?admin=edit_user&id=1
Amber
+1  A: 

Try changing the order of your rules and don't forget the [L] flag at the end :

RewriteRule ^admin/(.*)/id-(.*)$ index.php?admin=$1&id=$2 [L]

RewriteRule ^admin/(.*)$ index.php?admin=$1 [L]
Delapouite
+1  A: 

The expression .* is too general as it matches an arbitrary length of arbitrary characters. A better expression would be [^/]+ that matches only one ore more arbitrary characters except / (path segments separator).

So try these rules:

RewriteRule ^admin/([^/]+)$ index.php?admin=$1
RewriteRule ^admin/([^/]+)/id-([^/]+)$ index.php?admin=$1&id=$2

For the second rule you could also replace the second [^/]+ with [1-9][0-9]* that would match only integers greater than 0.

RewriteRule ^admin/([^/]+)/id-([1-9][0-9]*)$ index.php?admin=$1&id=$2
Gumbo
A: 

try this:

RewriteRule /admin/([^/]*)/?(id-(.*))?$ index.php?admin=$1&id=$3
Josh