Reputation: 201
I am currently messing around with my .htaccess file to get my URLs to look a tad cleaner. I managed to figure it out with one variable, so I successfully changed:
http://domain.com/index.php?role=Top
into:
http://domain.com/lane/Top
and my .htaccess page to do that looks like:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1
Now what I'm trying to figure out is how to make:
http://domain.com/result.php?champ1=foo&champ2=bar
into:
http://domain.com/matchup/foo&bar
is there a way to do that in my .htaccess file?
Upvotes: 0
Views: 97
Reputation: 784998
You can use:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^lane/(\w+)/?$ index.php?role=$1 [L,QSA,NC]
RewriteRule ^matchup/(\w+)&(\w+)/?$ result.php?champ1=$1&champ2=$2 [L,QSA,NC]
Upvotes: 0
Reputation: 4066
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1
# new rewrite rule
RewriteRule ^ matchup/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
Upvotes: 0
Reputation: 1063
You simply need to add another capture group to the regular expression:
RewriteRule ^lane/(\w+)/(\w+)$ ./result.php?champ1=$1&champ2=$2
Would result in being able to do:
http://domain.com/matchup/foo/bar
Or specifically what you requested:
RewriteRule ^lane/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
Each part of the expression that is inside braces () is defined as a capture group. So this is the part that is extracted and pushed into the target string as $1, $2, etc...
Upvotes: 3