@@ -748,13 +748,13 @@ local replace_server_vars = function(str, track_used_headers)
748748 if first_five == ' http_' then -- %{HTTC_*}, e.g. %{HTTC_HOST}
749749 replace = ngx .var [svar ] or ' '
750750 if track_used_headers then
751- table.insert (used_headers , svar :sub (6 ):gsub (' _' , ' -' ):lower ())
751+ table.insert (used_headers , ( svar :sub (6 ):gsub (' _' , ' -' ):lower () ))
752752 end
753753 elseif first_five == ' http:' then -- %{HTTP:*}, e.g. %{HTTP:Content-Type}
754754 svar = svar :sub (6 ):gsub (' -' ,' _' ):lower ()
755755 replace = ngx .var [' http_' .. svar ] or ' '
756756 if track_used_headers then
757- table.insert (used_headers , svar :gsub (' _' , ' -' ))
757+ table.insert (used_headers , ( svar :gsub (' _' , ' -' ) ))
758758 end
759759 elseif first_five == ' time_' then -- %{TIME_*}, e.g. %{TIME_YEAR}
760760 svar = svar :sub (6 )
@@ -813,7 +813,12 @@ local current_dir
813813local stat_instructions_used = {}
814814local stat_blocks_used = {}
815815for statement in htaccess :gmatch (' [^\r\n ]+' ) do
816- if statement :sub (1 ,1 ) == ' <' then
816+ -- Trim leading whitespace
817+ statement = statement :gsub (" ^%s*" , " " );
818+
819+ if statement :sub (1 ,1 ) == ' #' then
820+ -- Comment, so ignore it
821+ elseif statement :sub (1 ,1 ) == ' <' then
817822 -- handle blocks
818823 if statement :sub (2 ,2 ) ~= ' /' then
819824 -- opening tag <...>
@@ -987,6 +992,7 @@ for statement in htaccess:gmatch('[^\r\n]+') do
987992 pop_ctx ()
988993 end
989994 end
995+
990996 else
991997 local instruction = statement :match (' ^[^%s]+' )
992998 if instruction then
@@ -1207,11 +1213,9 @@ if get_cdir('rewrite') and #parsed_rewriterules > 0 then
12071213 elseif flag == ' qsa' or flag == ' qsappend' then -- [QSA]
12081214 local qs = relative_uri :match (' %?.*' )
12091215 if qs then
1210- local new_qs = dst :match (' %?.*' )
1216+ local new_qs = dst :match (' %?.*' )
12111217 if new_qs then
12121218 dst = dst :gsub (' %?.*' , ' ' , 1 ).. qs .. ' &' .. new_qs :sub (2 )
1213- else
1214- dst = dst .. new_qs
12151219 end
12161220 end
12171221 elseif flag == ' qsd' or flag == ' qsdiscard' then -- [QSD]
@@ -1222,6 +1226,10 @@ if get_cdir('rewrite') and #parsed_rewriterules > 0 then
12221226 else
12231227 fail (' Invalid flag value: [' .. rawflag .. ' ], expecting a number' )
12241228 end
1229+ elseif flag == ' e' then -- [E=]
1230+ -- Trying to set or unset an environment variable
1231+ -- https://httpd.apache.org/docs/2.4/rewrite/flags.html
1232+ fail (' RewriteRule flag E is unsupported' )
12251233 else
12261234 fail (' Unsupported RewriteRule flag: ' .. flag )
12271235 end
0 commit comments