Unable to rewrite URL for subdomain

#1
Hi,

I have below scenario.

I have my main site at https://www.example.com and i have a subdomain at https://st1.example.com
Main site document root is /home/example.com/public_html &
subdomain document root is changed to /home/example.com/subdomains/cdn/

Basically i am serving static content through self hosted subdomain on the sam server.

I have external redirects set for
/wp-includes/js
/wp-includes/css
&
wp_content_url is set to https://st1.example.com/static because i have symlinks in /home/example.com/subdomains/cdn/ folder pointing to main public html folders.


-rw-r--r-- 1 root root 589 Apr 3 12:33 .htaccess
lrwxrwxrwx 1 dad dad 46 Apr 1 15:01 inc -> /home/example.com/public_html/wp-includes/
-rw-r--r-- 1 dad dad 748 Apr 1 15:12 index.html
lrwxrwxrwx 1 dad dad 43 Apr 1 15:01 lib -> /home/example.com/public_html/wp-admin/
-rw-r--r-- 1 root root 250 Apr 1 17:22 robots.txt
lrwxrwxrwx 1 dad dad 53 Apr 1 15:01 static -> /home/example.com/public_html/sites/example/assets/ <--- wp-content folder is changed


So all js/css content is being served through st1.example.com


====PROBLEM is when i enable CDN on LSCACHE plugin on wordpress.===

there is folder where all minified files are served from.

Without CDN all these minified files are served from https://www.example.com/min/1nds.js or sdfs.css

When CDN is enabled from the plugin it rewrites this URL to https://st1.example.com/min/1nds.js which is correct but i am having hard time trying to rewrite or redirect this url to actual content on the site.

so basically https://st1.example.com/min/1nds.js should go to https://st1.example.com/static/cache/js/1nds.js which is

/home/example.com/subdomains/cdn/static/cache/js/1nds.js. <--- note that "static" is a symlink to /home/example.com/public_html/sites/example/assets/

I tried to rewrite URL with context as well as htaccess without any luck.


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

This works in normal wordpress where https://www.example.com/min/1nds.js is loaded correctly

but it does not work with https://st1.example.com/min/1nds.js


I also tried to create below context
URI - exp:^min/(\w+)\.(css|js)
Location - $DOC_ROOT/static/cache/$2/$1.$2

Also tried / context with above rewrite rule is.
URI - /
Location - $DOC_ROOT/
RewriteRule - Enabled
Rule - RewriteRule min/(\w+)\.(css|js) static/cache/$2/$1.$2 [L]


None of the above works for URL https://st1.example.com/min/1nds.js so i get 404 all the time.


When i enabled HIGH debug log level found out that server is looking for a file at /home/example.com/subdomains/min/js/1nds.js and this location does not exist and returns 404
 
#4
OMG it worked.
Created a static context /

URI: /
Location: $DOC_ROOT/
Accessible: Yes
RewriteBase: Yes
RewriteRule: RewriteRule min/(\w+)\.(css|js)$ static/cache/$2/$1.$2 [L]

And as @eaonflux said sudo service lsws restart.

Somehow forced restart from the OLS GUI did not work. so make sure to do it from the terminal.


This way there is no need of .htaccess in your local subdomain which is meant to server static files only.
 

mcbsys

New Member
#5
That tip about doing the restart from the terminal solved my problem too. This .htaccess rule on the base of my subdomain would not work with a graceful restart from the GUI but after "sudo service lsws restart ", it started working:

RewriteRule /* https://www.mydomain.com/blog/ [L,R=301]

Can someone explain the difference between the command line and the GUI restart?
 
Top