How do i mix these RewriteRules into a single line, with every 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]

In my opinion that .* instantly necessitates the next block otherwise it's taken too, so that you can replace by using [^/]+ however, if I actually do that on a single line (getting rid of basically the very first rule), it reduces?

You might be disappointed due to there being no solution of the items you are requesting.

Furthermore for every (n+1) subdir the variable title changes... so there's certainly no solution.

Anyway you are able to lower your RewriteRules utilizing a factor like:

RewriteRule ^([^/]*)(/([^/]*))?/ index.php?_page=$1&_sub=$2 [NC,QSA,L]

making the 2nd argument empty but matches both a couple of arguments.

Your rexexp ^app/?([\w]+)?/?([\w]+)?/?([\w]+)?/?((.*?)+)?$ is semantically dissimilar to your beginning cascade.

  • Where did the application using the optional / originate from?
  • How can you wan to process non-word figures for example "."?
  • The non-greedy operator ([w]+)?/ is redundant
  • How about additional parameters pseudo-sites?

Anyway in regexp terms the greedy ([^/]*) is much better as this works correctly having a /?.

RewriteRule ^([^/]*)/?^([^/]*)/?^([^/]*)/?^([^/]*)$ index.php?_page=$1&_sub=$2_area=$3&_ex=$4 [NC,QSA,L]