.htaccess not loading on subdirectory (2 levels)

#1
Hello guys, how are you? =)

I'm working on hundreds of OLS installations for a managed cloud hosting, and I started to notice a common problem:
If I have the following dir structure, the last .htaccess doesn't get read:
/srv/user/www/.htaccess
/srv/user/www/dir1/.htaccess
/srv/user/www/dir1/dir2/.htaccess

I have to move the dir2/.htaccess content to dir1/.htaccess and change the RewriteBase and RewriteRules to apply any rule to dir2/

I have a Wordpress generated .htaccess on www/.htaccess
Then I have a single rule .htaccess on dir1/.htaccess redirecting all requests to dir1/info.php
And finally I have another single rule .htaccess on dir1/dir2/.htaccess redirecting all requests to dir1/dir2/info.php

When I try to access something on dir1/dir2 in the browser, I got the following log:

2019-07-30 11:37:25.590607 [INFO] RewriteFile [/srv/user/www/.htaccess] parsed, return 0.
2019-07-30 11:37:37.799877 [INFO] RewriteBase [/dir1/] parsed, set to HttpContext 0x266a490.
2019-07-30 11:37:37.800335 [INFO] RewriteFile [/srv/user/www/dir1/.htaccess] parsed, return 0.

OLS is not parsing any .htaccess after the first subdirectory, it seems. Is this a known limitation, or is it a bug?
 
#2
If you are using ols 1.5.3, can you try run command
/usr/local/lsws/admin/misc/testbeta.sh 1.5.4
to use my latest version which just fixed a autoloadhtaccess bug?
 
#3
Oh right, I forgot to say. I'm using OLS 1.4.49 :/
I tried the 1.5.4 now, but no luck yet. I even tried to remove the dir1/.htaccess and leave only dir1/dir2/.htaccess, but same thing. The .htaccess from dir2 never gets read.
 
Last edited:
#5
Yeah, still not working :/
2019-07-31 15:11:28.963382 [NOTICE] [Child: 31635] LiteSpeed/1.4.50 Open starts successfully!
2019-07-31 15:11:35.841520 [INFO] RewriteBase [/dir1/] parsed, set to HttpContext 0x10c7d00.
2019-07-31 15:11:35.841665 [INFO] RewriteFile [/srv/xxxxxxxxxx/www/dir1/.htaccess] parsed, return 0.

Still not reading .htaccess on dir1/dir2
 
#7
Yep, on my vhost I have the following:

Code:
rewrite  {
  enable                  1
  autoLoadHtaccess        1
}
Like I said, every .htaccess is being load at root and root/firstDir. Only when the htaccess is inside another directory it doesn't load, like root/firstDir/secondDir/.htaccess
I tried on Ubuntu 14, 16 and 18. I can try on CentOS 7 too, if you want...

Here is my dir structure:

Code:
root@:/srv/xxxxxxx/www# find dir1
dir1
dir1/info.php
dir1/.htaccess
dir1/dir2
dir1/dir2/info.php
dir1/dir2/.htaccess
 
#11
Yes, setting a context works. I tried this:
Code:
context /dir1/dir2 {
allowBrowse             1
  rewrite  {
    enable                  1
    autoLoadHtaccess        1
  }
}
2019-07-31 16:03:21.381490 [INFO] RewriteFile [/srv/XXXXX/www/dir1/dir2/.htaccess] parsed, return 0.

And the rewrite worked.
 
#13
it also worked

2019-07-31 16:13:01.903635 [INFO] [config:server:vhosts:vhost:xxxxxxxxx] config context /dir1/dir2.
2019-07-31 16:13:01.903747 [INFO] RewriteFile [/srv/xxxxxxxxx/www/dir1/dir2/.htaccess] parsed, return 0.
 
#15
Oh, ok, so it is a known limitation... =)
I will talk to our staff so they know they should create a context to fix any .htaccess not being read.

Thanks!
 
#17
If you can set debug log to debug
Code:
errorlog logs/error.log {
  logLevel                DEBUG
  debugLevel              10
  rollingSize             10M
  enableStderrLog         1
}
You may see the context of .../dir2/ will be auto created when first time access a file inside, and you may see log about loading the .htaccess.
If you see it, can you tell me.
Actually this feature is designed to be this way.
 
#18
Hi, sorry the delay, was out of office already. =/

So, I disabled the previous context and enable the log to debug as you asked. The context of /dir2/ wasnt created.
When I requested something from dir1/dir2, only dir1 context is created:

Code:
2019-08-01 10:51:17.437870 [NOTICE] [Child: 15211] LiteSpeed/1.4.50 Open starts successfully!
2019-08-01 10:51:44.086451 [INFO] RewriteBase [/dir1/] parsed, set to HttpContext 0x2865d60.
2019-08-01 10:51:44.086842 [INFO] RewriteFile [/srv/xxxxx/www/dir1/.htaccess] parsed, return 0.
 
#19
I mean it should be auto created when first time access a file inside dir2, but not at the beginning time.
I will do more testing to make it work.
BTW what type of file you are accessing in dir2?
 
#20
This is the .htaccess content on dir1:
Code:
RewriteBase /dir1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ info.php [L,QSA]
And this is the .htaccess content on dir2:
Code:
RewriteBase /dir1/dir2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ info.php [L,QSA]
dir1/info.php returns:
This is a PHP file on dir1

dir1/dir2/info.php returns:
This is a PHP file on dir2

Any request on dir1/, for example, dir1/adfigadf returns:
This is a PHP file on dir1

With a context set to /dir1/dir2, any request to dir1/dir2 returns:
This is a PHP file on dir2

Without the context block, any request to dir1/dir2 returns:
This is a PHP file on dir1

When we removed the context block, the only .htaccess parsed when something is requested on dir2 is the .htaccess from dir1. If I create a context block like u suggested before, then the .htaccess from dir2 is parsed and the request returns "file on dir2".

I tried to remove RewriteBase from the .htaccess, same result.
 
Top