user2368299
user2368299

Reputation: 369

mod_rewrite url with 2 params or more

URL: http://example.com/good_game/osmp/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /?service=$1&terminal=$2 [L,QSA]

i receive

Array ( [service] => good_game [terminal] => /osmp/ )

i need

Array ( [service] => good_game [terminal] => osmp )

and what RewriteRule i need for multiparams?

Upvotes: 0

Views: 38

Answers (2)

James McDonald
James McDonald

Reputation: 56

A RewriteRule like:

RewriteRule ^/([^/]*)/([^/]*)/?$ /?service=$1&terminal=$2 [L,QSA]

Should do what you need. Basically, put the characters you don't want in your parameters outside the () to avoid capturing them.

Upvotes: 1

Prix
Prix

Reputation: 19528

This should give u what you want:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?service=$1&terminal=$2 [L,QSA]

Your problem with your rule is that you're using (.*) after your first group so it will get anything left by that group which is /anything/.

So basically your rule is telling the server to get anything not a / so it gets good_game, then you're asking it to get anything left so it gets /osmp/.

Upvotes: 1

Related Questions