.htaccess - shorten/compress mod_rewrite rules -
amongst rules have..
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2&info=$3&id=$4 [qsa,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2&info=$3 [qsa,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2 [qsa,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/\.]+)/?$ index.php?page=$1 [qsa,l]
which seems little bulky me , repeats lot of stuff, ideas on how can shorten it?
can set "global" conditions? can have 1 rule captures ones below (i dont care if sends through empty varibles)
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule **clever stuff here** index.php?page=$1&submenu=$2&info=$3&id=$4 [qsa,l]
so capture
domain.com/a/b/c/d , domain.com/a/b/c , domain.com/a/b , domain.com/a
answers, thoughts, musings, , existential arguments appreciated...
you can pretty remove conditions if check inverse , let pass through rewrite engine. afterwards know isn't existing file or directory:
rewritecond %{request_filename} -f [or] rewritecond %{request_filename} -d rewriterule ^ - [l] rewriterule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2&info=$3&id=$4 [qsa,l] rewriterule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2&info=$3 [qsa,l] rewriterule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&submenu=$2 [qsa,l] rewriterule ^([^/\.]+)/?$ index.php?page=$1 [qsa,l]
it's not fancy multiple-look-ahead regex in 1 line, make easier read.
edit:
well, said, multiple look-aheads, like:
rewriterule ^(?:([^/.]+)|)(?:/([^/.]+)|)(?:/([^/.]+)|)(?:/([^/.]+)|) index.php?page=$1&submenu=$2&info=$3&id=$4 [qsa,l]
but it's harder read, , more unexpected if change something. additionally, whereas having explicit 4 different mappings, don't blank query string params look-aheads. whether last (?:/([^/.]+)|)
there or not, still id
param (just blank).