Firstly I asked this question on stack to get url rewriting working. I extended this to include a 3rd parameter however I failed when this 3rd parameter is different.
I have created a list of a few urls I currently have with their GET parameters and what I want to turn them into:
~/tournament/profile/username /tournament/index.php?view=profile&id=username
~/tournament/profile/username/edit /tournament/index.php?view=profile&id=username&action=edit
~/tournament/profile/username/overview /tournament/index.php?view=profile&id=username&page=overview
~/tournament/profile/username/teams /tournament/index.php?view=profile&id=username&page=teams
~/tournament/teams/create /tournament/index.php?view=teams&action=create
~/tournament/teams/teamname /tournament/index.php?view=teams&id=teamname
~/tournament/teams/teamname/edit /tournament/index.php?view=teams&id=teamname&action=edit
~/tournament/teams/teamname/delete /tournament/index.php?view=teams&id=teamname&action=delete
~/tournament/teams/teamname/members /tournament/index.php?view=teams&id=teamname&page=members
~/tournament/cups /tournament/index.php?view=cups
~/tournament/cups/id /tournament/index.php?view=cups&id=cupid
~/tournament/cups/id/rules /tournament/index.php?view=cups&page=rules
~/tournament/cups/id/matches /tournament/index.php?view=cups&page=matches
~/tournament/cups/id/brackets /tournament/index.php?view=cups&page=brackets
~/tournament/cups/id/teams /tournament/index.php?view=cups&page=teams
~/tournament/passwords/forgot_password /tournament/index.php?view=password&action=forgot_password
~/tournament/passwords/reset /tournament/index.php?view=password&action=reset
~/tournament/admin /tournament/admin.php
~/tournament/admin/users /tournament/admin.php?view=users
~/tournament/admin/users/username /tournament/admin.php?view=users&id=username
using the following .htaccess:
RewriteEngine On
RewriteBase /tournament/
# Skip if existing file/folder
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)\s [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)&action=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2/$3? [R=301,L]
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)&page=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2/$3? [R=301,L]
RewriteRule ^([^/]+)$ index.php?view=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?view=$1&id=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?view=$1&id=$2&action=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?view=$1&id=$2&page=$3 [L]
mostly focusing on the urls regarding /profile/username/edit
and /profile/username/overview
.
I added in the following rules:
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)&page=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2/$3? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?view=$1&id=$2&page=$3 [L]
to deal with the &page
parameter however when my url rewrites to /profile/username/team/overview
I get my edit page back rather than the overview page.
What is the most efficient way to deal with interchanging variables? i.e.
?view=*&id=*&action=*
vs ?view=*&id=*&page=*
Thanks again.