Reputation: 13
I am trying to rewrite the following 3 URLs to translate into the correct pages.
highscore.php is in my main directory
www.domain.com/clan/
www.domain.com/highscore.php
www.domain.com/clan/Halos
www.domain.com/highscore.php?clan=Halos
www.domain.com/clan/Halos/Cooking
www.domain.com/highscore.php?clan=Halos&view=Cooking
I have the following in my .htaccess:
RewriteEngine On
#RewriteBase /
RewriteRule ^clan/([^/]*)$ /highscore.php?clan=$1&view=$2 [L]
This successfully maps the following URL:
www.domain.com/clan/Halos
to
www.domain.com/highscore.php?clan=Halos
The following URL goes to the highscore.php page with a null 'clan' parameter
www.domain.com/clan/
is mapping to
www.domain.com/highscore.php?clan=
I'm trying to get it to map to
www.domain.com/highscore.php
When I go to
www.domain.com/clan/Halos/Cooking
It only recognizes the first parameter 'Halos' and not the second one 'Cooking' ? It takes me to:
www.domain.com/highscore.php?clan=Halos
Very confused, I need some direction to what I'm doing right and/or wrong.
Upvotes: 0
Views: 154
Reputation: 1402
RewriteEngine On
#RewriteBase /
#Rewrite base path
RewriteRule ^clan/$ /highscore.php [L]
#Rewrite clan path
RewriteRule ^clan/([^/]*)$ /highscore.php?clan=$1 [L]
#Rewrite view path
RewriteRule ^clan/([^/]*)/([^/]*)$ /highscore.php?clan=$1&view=$2 [L]
Upvotes: 1
Reputation: 1063
Your rewrite rule doesn't have a second extracted portion in the expression, so only one parameter is extracted. Here's how you would extract a second parameter:
RewriteRule ^clan/([^/]*)/([^/]*)$ /highscore.php?clan=$1&view=$2 [L]
Now you're extracting two parts here (denoted by the brackets).
Upvotes: 0