.htaccess - htaccess simplified and remove need for trailing a slash -
i writing first htaccess , cleaning , understanding it. first issue having mulitple parameters. current setup looks like:
options +followsymlinks rewriteengine on rewritecond %{request_filename} !/(_modules|css|files|ico|img|js)/ rewriterule ^([^/]*)$ index.php?p1=$1 [l] rewritecond %{request_filename} !/(_modules|css|files|ico|img|js)/ rewriterule ^([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2 [l] rewritecond %{request_filename} !/(_modules|css|files|ico|img|js)/ rewriterule ^([^/]*)/([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2&p3=$3 [l] rewritecond %{request_filename} !/(_modules|css|files|ico|img|js)/ rewriterule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ index.php?p1=$1&p2=$2&p3=$3&p4=$4 [l]
is there way simplify handle maximum of 4 parameters of them being optional? leads me me next problem seems if need have trailing slash after parameters unless using 4 parameters.
in short urls this...
http://www.example.com/home http://www.example.com/home/ http://www.example.com/blog/i-am-a-title http://www.example.com/blog/i-am-a-title/ http://www.example.com/varable1/varable2/varable3/varable4 http://www.example.com/varable1/varable2/varable3/varable4/
i'll appreciate can provide.
well sort of experiment, work have said believe there may better way this:
rewritecond %{request_filename} !/(index\.php|_modules|css|files|ico|img|js)/ rewriterule ^(([^/]*)/?)(([^/]*)/?)(([^/]*)/?)(([^/]*)/?)$ /index.php?p1=$2&p2=$4&p3=$6&p4=$8 [l]
basically adding group per entry can safely exclude non existent group.
so first element required , $2
, second element becomes $4
, third element becomes $6
, last element becomes $8
.
(([^/]*)/?)
means not /
ends or not /
outer group , inner group not /
.
simplified rule bit more:
rewritecond %{request_filename} !/(index\.php|_modules|css|files|ico|img|js)/ rewriterule ^([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|) /index.php?p1=$1&p2=$2&p3=$3&p4=$4 [l]
Comments
Post a Comment