[SOLVED]: Apache "<If>", "<ElseIf>", "<Else>" not supported?

#1
Hello,

Since Apache 2.4.26 (somewhen in 2012), the httpd webserver core supports the directives "<If>", "<ElseIf>" and "<Else>", to allow for easy handling of requests based on logical conditions, without using the RewriteEngine or any other modules. These directives are evaluated at request time, according to the Apache docs:

https://httpd.apache.org/docs/2.4/mod/core.html#if

While testing this with Litespeed, it appears that Litespeed silently ignores any lines containing these core directives when used with Apache configuration files (as we do on Plesk based servers).

Since it has been supported by the Apache core for about 10 years now, I think it would be a very nice and welcome addition to Litespeed as well. So, missing support for this feels like a bug to me ;) but if it seems more like a feature request, please feel free to move this thread to the relevant forum...

In any case, I would suggest adding this to Litespeed, so we can use this to improve functionality on our Hosting environments.

With kind regards,

Hindrik Deelstra
 

mistwang

LiteSpeed Staff
#3
"<if> ... <else> ..." should be supported, maybe not perfect, most common directives are supported. Please make sure you are using the latest version.
Please post your test cases if need.
 
#4
Hmm, it appears the same issue I posted a thread about, with the RewriteRules and RewriteOptions not inheriting to child directories...

If I add these directives to a .htaccess file in the vhosts's DocumentRoot, all seems to work just fine. RewriteRules and "<If>" directives alike.

However! When placing these directives in a .htaccess file in a directory *above* the DocumentRoot, all directives seem to be just ignored/skipped. This is the same inheritance problem I mentioned in:

https://www.litespeedtech.com/suppo...s-do-not-inherit-correctly.20879/#post-120963

When using Apache as webserver, everything works as intended, and the .htaccess files are processed in order of descending hierarchy, as is mandated by Apache's inheritance logic. So, if I have a .htaccess file in "/var/www/vhosts" for example, it's directives are processed first. If the path traversal encounters another .htaccess file in, let's say "/var/www/vhosts/<domainname>/httpdocs", those directives are then subsequently processed. This continues along all the directories in the entire path before reaching the ultimate destination from which the request is served.

In this way, it is possible to declare some general directives in a directory higher up, and have those optionally overridden in a lower down directory's .htaccess file.

This mechanism seems to be non-functional in Litespeed. Unless I am doing something specifically wrong, it appears as a shortcoming in Litespeed's handling of accepted .htaccess hierarchy as defined/used by Apache.

Please help me to understand why this is not working with Litespeed, and only with Apache.

With kind regards

Hindrik Deelstra
 
#6
Well, Litespeed does indeed support the directives themselves, but it seems to not inherit them the correct way when used in hierarchical .htaccess files. That seems like an issue that needs to be resolved, especially since Litespeed (cl)aims to be a drop-in replacement for Apache, and supports parsing all of Apache's configuration files...

If it does not work 100%, it should be considered as a bug, and addressed accordingly, or else Litespeed is not the product it claims to be...

Please see if you can reproduce this issue, and if so, address this in a hotfix or future release.

With kind regards,

Hindrik Deelstra
 

Pong

Administrator
Staff member
#7
Can you give an example of such an inheritance not working? I would recommend you create a separate thread to discuss and leave this thread to be
"<If>", "<ElseIf>", "<Else>
related.
 
Last edited:

mistwang

LiteSpeed Staff
#8
That's as designed. LiteSpeed tries to avoid the inefficiency of Apache's .htaccess implementation. It is intentional to stop .htaccess inheritance beyond user's home directory.
For purpose to apply common config, add it to Apache main config with <Directory /var/www/vhosts/> ... </Directory>, it is more efficient.
 
#9
Hi mistwang,

Thanks for your clarification! I was just about to create a new bug report, as I indeed ran into the issue of non-inheritance of .htaccess files placed higher up than the user's home-directory!

I think I may have missed something earlier, but after carefully re-examining, and rebuilding my testing setup, I've come to the conclusion that the .htaccess inheritance seems to work just as we intend it to be used, but I was mistakenly also testing this outside the user-homedir, which led to my confusion and frustration ;)

With your addition that Litespeed intentionally ignores .htaccess files outside of user-homes, I have confirmation and an explanation of my issues, and can indeed use a general Apache conf file to apply our desired directives for all vhosts.

So, I'll mark this thread as solved, and thank you for your support!

With kind regards,

Hindrik Deelstra
 
Top