Incorrect .htaccess file updated if wordpress files are in separate folder

#1
There is an error that prevents caching if wordpress is in separate folder then index.php. If there is a .htaccess file in the WP folder, then the .htaccess in that folder is incorrectly updated. The .htaccess in the route will be ignored and no caching rules are written.
 

Pong

Administrator
Staff member
#2
How did you enable cache? Through LSCWP plugin? maybe you need to log a ticket with tmp root for us to check your situaiton.
 

qtwrk

Well-Known Member
#7
Hi,

Could you please try add

Code:
define( 'LITESPEED_WP_REALPATH', '/wordpress' ) ;
to your wp-config.php and see how it goes ?

Best regards,
 
#8
I can confirm that the above does not resolve the issue. To reproduce: Place Wordpress files in a folder /wordpress (wordpress address) and add a .htacces file to that folder. Then update LITESPEED settings and the below code will be added to the /wordpress .htacccess file instead of the .htaccess file in the root (site address):

Code:
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule ^min/\w+\.(css|js) - [E=cache-control:no-vary]

### marker CACHE RESOURCE start ###
RewriteRule cms_files/wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
### marker MINIFY start ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)$
RewriteCond %1/wp-content/cache/$2/$1.$2 -f
RewriteRule min/(\w+)\.(css|js) wp-content/cache/$2/$1.$2 [L]
</IfModule>
### marker MINIFY end ###

## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE
 
Last edited by a moderator:
#10
Yes without URL change. The site is in the root and wordpress address = /whatever

1 (without change of SITE-URL (remains example.com) == (site address)
 

qtwrk

Well-Known Member
#11
Hi,

I am trying to reproduce it but unsuccessful

this is what I did:

1. install a WP , and LSCWP on root domain ,check and make sure caching is working.

2. follow the document , move the WP to sub-directory

3. edit the .htaccess in root folder per document instructed

4. check the new configuration , I can see x-litespeed-cache hit header

5. edit the LSCWP make it write rules into htaccess (in my case, JS/CSS combine minify)

6. check both root htaccess and subdirectory htaccess but they appear as it should be.

Code:
[root@cpanel public_html]# ls -la
total 4
drwxr-x--- 1 testuser nobody     58 May 27 17:52 .
drwx--x--x 1 testuser testuser 392 May 27 17:36 ..
-rw-r--r-- 1 testuser testuser 623 May 27 17:52 .htaccess
drwxr-xr-x 1 testuser testuser  28 May 27 17:31 .well-known
drwxr-xr-x 1 testuser testuser 666 May 27 17:51 wordpress
content of root htaccess

Code:
[root@cpanel public_html]# cat .htaccess


# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?test.domain.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?test.domain.com$
RewriteRule ^(/)?$ wordpress/index.php [L]
and the one in subdirectory

Code:
[root@cpanel public_html]# cat wordpress/.htaccess
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule ^min/\w+\.(css|js) - [E=cache-control:no-vary]

### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
### marker MINIFY start ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)$
RewriteCond %1/wp-content/cache/$2/$1.$2 -f
RewriteRule min/(\w+)\.(css|js) wp-content/cache/$2/$1.$2 [L]
</IfModule>
### marker MINIFY end ###

## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
Best regards,
 
#12
Thanks for the update.

The issue is that having done the above: If you now update the expire time in litespeed settings you will see that the .htaccess in /wordpress is updated and the .htaccess in the root is not updated.
 

qtwrk

Well-Known Member
#13
Hi,

Yes, I can confirm that, but the expires header works that way

Code:
[root@cpanel public_html]# cat .htaccess


# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?test.domain.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?test.domain.com$
RewriteRule ^(/)?$ wordpress/index.php [L]
</IfModule>

and wordpress htaccess

Code:
[root@cpanel public_html]# cat wordpress/.htaccess
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule ^min/\w+\.(css|js) - [E=cache-control:no-vary]

### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
### marker BROWSER CACHE start ###
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType application/pdf A15552000
ExpiresByType image/x-icon A15552000
ExpiresByType image/vnd.microsoft.icon A15552000
ExpiresByType image/svg+xml A15552000

ExpiresByType image/jpg A15552000
ExpiresByType image/jpeg A15552000
ExpiresByType image/png A15552000
ExpiresByType image/gif A15552000
ExpiresByType image/webp A15552000

ExpiresByType video/ogg A15552000
ExpiresByType audio/ogg A15552000
ExpiresByType video/mp4 A15552000
ExpiresByType video/webm A15552000

ExpiresByType text/css A15552000
ExpiresByType text/javascript A15552000
ExpiresByType application/javascript A15552000
ExpiresByType application/x-javascript A15552000

ExpiresByType application/x-font-ttf A15552000
ExpiresByType application/x-font-woff A15552000
ExpiresByType application/font-woff A15552000
ExpiresByType application/font-woff2 A15552000
ExpiresByType application/vnd.ms-fontobject A15552000
ExpiresByType font/ttf A15552000
ExpiresByType font/woff A15552000
ExpiresByType font/woff2 A15552000

</IfModule>
### marker BROWSER CACHE end ###

### marker MINIFY start ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)$
RewriteCond %1/wp-content/cache/$2/$1.$2 -f
RewriteRule min/(\w+)\.(css|js) wp-content/cache/$2/$1.$2 [L]
</IfModule>
### marker MINIFY end ###

## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
Code:
[root@cpanel public_html]# curl -I -XGET http://test.domain.com/wp-includes/css/dist/block-library/theme.min.css?ver=5.2.1
HTTP/1.1 200 OK
Connection: Keep-Alive
Cache-Control: public, max-age=15552000
Expires: Sat, 23 Nov 2019 16:15:52 GMT
Content-Type: text/css
Last-Modified: Mon, 27 May 2019 15:49:24 GMT
Accept-Ranges: bytes
Content-Length: 1495
Date: Mon, 27 May 2019 16:15:52 GMT
Server: LiteSpeed

and if I directly curl the static file in wordpress URI

Code:
[root@cpanel public_html]# curl -I -XGET http://test.domain.com/wordpress/wp-includes/css/dist/block-library/theme.min.css?ver=5.2.1
HTTP/1.1 200 OK
Connection: Keep-Alive
Cache-Control: public, max-age=15552000
Expires: Sat, 23 Nov 2019 16:16:16 GMT
Content-Type: text/css
Last-Modified: Mon, 27 May 2019 15:49:24 GMT
Accept-Ranges: bytes
Content-Length: 1495
Date: Mon, 27 May 2019 16:16:16 GMT
Server: LiteSpeed
Both shows 6 months of expiration.

Best regards,
 
#14
Cool.

Doesn't work for me on any site by checking in the browser , but hey, I just work around it at this stage so I not that bothered really.
 

qtwrk

Well-Known Member
#15
Hi,

Oh Okay , but it really curious me why it didn't work on your site, as on my test it was working as it should be.

By default LSCWP browser cache only expire in 1 month , I manually change it to 6 months just to make the difference more obvious.
 
Top