Code: Select all
RewriteEngine on
RewriteRule ^/(main|about|services|etc)/(.+)/(.+)$ /index.php?section=$1&page=$2&sub=$3 [QSA,L]
RewriteRule ^/(main|about|services|etc)/(.+)$ /index.php?section=$1&page=$2 [QSA,L]
RewriteRule ^/(main|about|services|etc)/$ /index.php?section=$1 [QSA,L]
RewriteRule ^/(main|about|services|etc)$ /index.php?section=$1 [QSA,L]At first I figured just adding the first rewrite rule would work, but if you go to any page with just 2 levels of rewriting, eg. /main/home/ it would cause an error where as /main/home/bla/ would be fine.
I was stumbled being my first time playing around with this, so I did some more research for a few hours and i couldn't find an easy solution. So I did the same rule without the 3rd level on the next line. And presto, the 2nd level url worked. Then the single level urls would give errors. Easy solution, another line with just 1 level. But then came the issue of single level urls causing errors if there was no trailing slash. So I added the 4th line.
So everything works. Just like I want. But is there an easier/more efficient way?