I have a series of links in my admin panel that look like this:
/admin-panel/index.php?foo=visual&bar=icons
/admin-panel/index.php?foo=visual&bar=templates
/admin-panel/index.php?foo=visual&bar=templates&baz=1
/admin-panel/index.php?foo=logs&bar=activity
/admin-panel/index.php?foo=logs&bar=transactions
/admin-panel/index.php?foo=logs&bar=transactions&baz=23
I want to use a structure:
/admin-panel/visual/icons
/admin-panel/visual/templates
/admin-panel/visual/templates/1
/admin-panel/log/activity
/admin-panel/logs/transactions
/admin-panel/logs/transactions/23
How do I structure the .htaccess file to hide the index.php name and assign the GET (foo, bar, baz) to their respective variables without rewriting the URL? Thank you!
CodePudding user response:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.php?foo=([^&] )&bar=([^&\s] ) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (^(?!.?.css$|.?.js$|.?.png$|.?.jpg$|.?.gif$|.?.pdf$|.?.ico$))(.)$ index.php?foo=$1&bar=$2 [L,QSA]
Usage = These rules will take url like /admin-panel/index.php?foo=visual&bar=icons to /admin-panel/visual/icons and so on.