How can I combine these RewriteRules into one single line, with each parameter being optional?
RewriteRule ^(.*)/(.*)/(.*)/(.*)/ index.php?_page=$1&_sub=$2&_area=$3&_ex=$4 [NC,QSA,L]
RewriteRule ^(.*)/(.*)/(.*)/ index.php?_page=$1&_sub=$2&_area=$3 [NC,QSA,L]
RewriteRule ^(.*)/(.*)/ index.php?_page=$1&_sub=$2 [NC,QSA,L]
RewriteRule ^(.*)/ index.php?_page=$1 [NC,QSA,L]
RewriteRule ^ index.php [NC,QSA]
I believe that .* automatically requires the next block otherwise it’s captured too, so you can replace that with [^/]+ however when I do that on one line (removing all but the first rule), it stops working?
You may be disappointed because there’s no solution of what you’re asking for.
Moreover for each (n+1) subdir the variable name changes… so there’s definitely no solution.
Anyway you can reduce your RewriteRules using a thing like:
which makes the second argument empty but matches both one or two arguments.