htaccess inheritance

#1
Hello,

We are experiencing an issue on a cPanel/CentOS 64-bit server where .htaccess files do not appear to be inherited. This was occurring with 4.0.19 Enterprise, and, following an upgrade and also a force-reinstall of 4.0.20, is still occurring.

given an htaccess file:
/home/username/public_html/.htaccess

and the rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]

any request for a nonexistent file or directory should be rewritten to a request for index.php. This happens in the given directory.

given a subdomain located at:
/home/username/public_html/subdomain

configured as a vhost in the httpd.conf, the rules are not working; going to a non-existent addresses throws a 404, though the htaccess is getting read in by lsws, according to the logs. If the .htaccess is copied the subdomain directory, it works without issue. On Apache httpd it is working without issue.

Here are the relevant log entries (with the bits referring to other rewrite rules in the same htaccess file removed):

[/usr/local/apache/conf/httpd.conf:4914] processing direcitve: CustomLog /usr/local/apache/domlogs/subdomain.address.com combined.
[/usr/local/apache/conf/httpd.conf:4915] processing direcitve: CustomLog /usr/local/apache/domlogs/subdomain.address.com-bytes_log "%{%s}t %I .\n%{%s}t %O .".
[/usr/local/apache/conf/httpd.conf:4918] processing direcitve: suPHP_UserGroup username username.
[/usr/local/apache/conf/httpd.conf:4921] processing direcitve: SuexecUserGroup username username.
[/usr/local/apache/conf/httpd.conf:4923] processing direcitve: ScriptAlias /cgi-bin/ /home/username/public_html/subdomain/cgi-bin/.
[:1] processing direcitve: php_admin_flag display_errors off.
[:1] add PHP config: display_errors off
[:2] processing direcitve: php_admin_flag safe_mode off.
[:2] add PHP config: safe_mode off
[:3] processing direcitve: RewriteEngine On.
[:3] enable rewrite engine: 1
[:4] processing direcitve: RewriteCond %{ENV:LS_AI_PATH} ^$.
[:5] processing direcitve: RewriteRule .*\.php - [F].
[10.1.252.108:64660-0#APVH_subdomain.address.com] Content len: 0, Request line: 'GET /login HTTP/1.1'
[10.1.252.108:64660-0#APVH_subdomain.address.com] Cookie len: 238, PHPSESSID=1f4c055877b6b6f8eda238a7384e139f; __utma=219045637.1895141871.1299041193.1299041193.1299041193.1; __utmb=219045637.10.10.1299041193; __utmc=219045637; __utmz=219045637.1299041193.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
[10.1.252.108:64660-0#APVH_subdomain.address.com] Find context with URI: [/], location: [/home/username/public_html/subdomain/]
[HTAccess] Updating configuration file [/home/username/public_html/subdomain/.htaccess]
[HTAccess] Updating configuration from [/home/username/public_html/subdomain/.htaccess]
[/home/username/public_html/subdomain/.htaccess:1] processing direcitve: Options +FollowSymLinks -Indexes.
[/home/username/public_html/subdomain/.htaccess:2] processing direcitve: RewriteEngine on.
[/home/username/public_html/subdomain/.htaccess:3] processing direcitve: RewriteBase /.
[/home/username/public_html/subdomain/.htaccess:14] processing direcitve: RewriteCond %{REQUEST_FILENAME} !-f.
[/home/username/public_html/subdomain/.htaccess:15] processing direcitve: RewriteCond %{REQUEST_FILENAME} !-d.
[/home/username/public_html/subdomain/.htaccess:16] processing direcitve: RewriteRule ^(.*)$ /index.php [L].
[10.1.252.108:64660-0#APVH_subdomain.address.com] Find .htaccess context with URI: [/], location: [/home/username/public_html/subdomain/]
[10.1.252.108:64660-0#APVH_subdomain.address.com] [REWRITE] Rewrite engine is not enabled for context '/'
[10.1.252.108:64660-0#APVH_subdomain.address.com] File not found [/home/username/public_html/subdomain/login]
[10.1.252.108:64660-0#APVH_subdomain.address.com] processContextPath() return 25
[10.1.252.108:64660-0#APVH_subdomain.address.com] processNewReq() return 25.
[10.1.252.108:64660-0#APVH_subdomain.address.com] HttpConnection::sendHttpError(),code=404 Not Found^M
[10.1.252.108:64660-0#APVH_subdomain.address.com] redirect to:
URI=[/404.shtml],
QueryString=[]
[10.1.252.108:64660-0#APVH_subdomain.address.com] Find context with URI: [/], location: [/home/username/public_html/subdomain/]
[10.1.252.108:64660-0#APVH_subdomain.address.com] Find .htaccess context with URI: [/], location: [/home/username/public_html/subdomain/]
[10.1.252.108:64660-0#APVH_subdomain.address.com] File not found [/home/username/public_html/subdomain/404.shtml]
[10.1.252.108:64660-0#APVH_subdomain.address.com] Error Page, processContextPath() return 25
[10.1.252.108:64660-0#APVH_subdomain.address.com] HttpConnection::flush()!
[10.1.252.108:64660-0#APVH_subdomain.address.com] Written to client: 617
[10.1.252.108:64660-0#APVH_subdomain.address.com] HttpConnection::nextRequest()!
 

mistwang

LiteSpeed Staff
#2
this should have been addressed in latest 4.0.20 package.
Please try a force reinstall from LSWS web console, under "Version Managment" page.
 

IrPr

Well-Known Member
#3
Are you sure that its implemented in Apache?

Lets assume that there is domain.tld VH which contains this rewrites:
Code:
RewriteCond %{HTTP_HOST} !^www\.domain\.tld
RewriteRule (.*) http://www.domain.tld/$1
Which forces to www links with redirection

Well, therefore any subdomains such as w00t.domain.tld get redirected into www.domain.tld
Also all RewriteRules inherits in deeper subdomain levels

For example if its a vBulletin with VBSEO rewrites all php links into vbseo.php which doesn't exists in subdomains and leads to 404 not found for all php files

George, i think its wrong feature and would be reverted
 
Last edited:

mistwang

LiteSpeed Staff
#4
As long as you put a rewrite related directive in subdomain .htaccess, the rewrite rules in parent directory will be ignored. That's the Apache behavior we observed.

Yes, that's true that what you described may cause trouble for subdomains, same for Apache.

We need to follow Apache's behavior even though it may not be a good one.
 

IrPr

Well-Known Member
#5
We need to follow Apache's behavior even though it may not be a good one.
Is it possible to have an option for disabling inheritance behavior for subdomains like before?
However its default apache's behavior but as you already mentioned its may not be a good idea and LSWS could provide better flexible peformances
 
Last edited:
#6
As long as you put a rewrite related directive in subdomain .htaccess, the rewrite rules in parent directory will be ignored. That's the Apache behavior we observed.

Yes, that's true that what you described may cause trouble for subdomains, same for Apache.

We need to follow Apache's behavior even though it may not be a good one.
A force-reinstall was done and verified version is 4.0.20. However, with NO .htaccess file present in the sub-directory, rewrite rules are not inherited from .htaccess in parent directory. Have also tried creating a .htaccess in sub-directory with only "RewriteEngine on" and "RewriteOptions inherit" to no avail...

Any further advice is much appreciated.

Regards,
 

mistwang

LiteSpeed Staff
#7
A force-reinstall was done and verified version is 4.0.20. However, with NO .htaccess file present in the sub-directory, rewrite rules are not inherited from .htaccess in parent directory. Have also tried creating a .htaccess in sub-directory with only "RewriteEngine on" and "RewriteOptions inherit" to no avail...

Any further advice is much appreciated.

Regards,
It must be something else, add "RewriteLogLevel 9" to subdomain configuraiton in httpd.conf, restart, then check error_log.
 

IrPr

Well-Known Member
#8
Dear George,
I'm looking forward for "RewriteOptions inherit" directive support

any chance to be implemented?
 
#10
Reading .htaccess from parent directory, above child VirtualHost's DocumentRoot

I think it has been supported already. If you find that it does not work properly, let us know.
The issue, as I am seeing it right now, is that the VirtualHost is not honoring the .htaccess in the parent directory (which is a different VirtualHost) as cPanel created the directory hierarchy.

Are these separated in the performance (or security) model, to not walk the directory tree up to the DocumentRoot for parent .htaccess files?

eg:

Code:
<VirtualHost 192.168.0.1>
 ServerName example.com
 DocumentRoot /var/www/example.com/htdocs
</VirtualHost>
Code:
<VirtualHost 192.168.0.1>
 ServerName test.example.com
 DocumentRoot /var/www/example.com/htdocs/test
</VirtualHost>
Will test.example.com ever read the .htaccess from /var/www/example.com/htdocs, or will it start at /var/www/example.com/htdocs/test? I can completely understand the reasoning behind starting at /var/www/example.com/htdocs/test for performance or even for security, but I am not sure if that fits in with the Apache methods that are expected (where every directory from / on up to the cwd are checked for an .htaccess).

An optional flag in Server->General->HT Access for "Apache style inherit" with a warning that it could impact performance would be nice to see.
 
#12
force reinstall 4.0.20

try "Force Reinstall" 4.0.20 from LSWS admin console "Version Management".
Please know that jpipkin, gbutler and myself are all from the same company. We have performed a force reinstall before the initial post, and again in post #6. I have again performed a force reinstall, with no discernible changes seen.

Anthony
 

mistwang

LiteSpeed Staff
#13
We have tested it in our lab under cPanel vhosts, it works fine.
Please add "RewriteLogLevel 9" to subdomain configuration, then post debug log like that in the first post, we will analyze what happens.
Sorry, I am not smart enough to figure out all of your three are from the same company.
 
#14
We have tested it in our lab under cPanel vhosts, it works fine.
Please add "RewriteLogLevel 9" to subdomain configuration, then post debug log like that in the first post, we will analyze what happens.
Sorry, I am not smart enough to figure out all of your three are from the same company.
The RewriteEngine, within the parent itself, was not being inherited from the global declaration. After adding RewriteEngine on into the parent .htaccess it does appear as though the rewrites are working as intended.

Thank you for your patience,
Anthony
 
Top