Rewrite Help

#1
I'm trying to get my Rewrite Rules to return files from whatever directory they exist in.

It seems to fail the file check even when the file actually exists.

This is my rewrite cond and rules:
Code:
RewriteCond /usr/local/lsws/i.kltv.co/app/public%{REQUEST_URI} -f
RewriteRule ^/?(.*)$ /usr/local/lsws/i.kltv.co/app/public/$1 [L]

RewriteCond /usr/local/lsws/i.kltv.co/app/uploads/thumbnails%{REQUEST_URI} -f
RewriteRule ^/thumbnails/?(.*)$ /usr/local/lsws/i.kltv.co/app/uploads/thumbnails/$1 [L]

RewriteCond /usr/local/lsws/i.kltv.co/app/uploads/files%{REQUEST_URI} -f
RewriteRule ^/?(.*)$ /usr/local/lsws/i.kltv.co/app/uploads/files/$1 [L]

RewriteCond /usr/local/lsws/i.kltv.co/app/uploads/images%{REQUEST_URI} -f
RewriteRule ^/?(.*)$ /usr/local/lsws/i.kltv.co/app/uploads/images/$1 [L]
This is the logs from OpenLiteSpeed:

Code:
[REWRITE] strip base: '/' from URI: '/a7DZyC.png'
[REWRITE] Rule: Match 'a7DZyC.png' with pattern '^/?(.*)$', result: 2
[REWRITE] stat( /usr/local/lsws/i.kltv.co/app/public/a7DZyC.png ) failed
[REWRITE] Rule: Match 'a7DZyC.png' with pattern '^/thumbnails/?(.*)$', result: -1
[REWRITE] Rule: Match 'a7DZyC.png' with pattern '^/?(.*)$', result: 2
[REWRITE] stat( /usr/local/lsws/i.kltv.co/app/uploads/files/a7DZyC.png ) failed
[REWRITE] Rule: Match 'a7DZyC.png' with pattern '^/?(.*)$', result: 2
[REWRITE] Cond: test '/usr/local/lsws/i.kltv.co/app/uploads/images/a7DZyC.png' with pattern '-f', result: 0
[REWRITE] Source URI: 'a7DZyC.png' => Result URI: '/usr/local/lsws/i.kltv.co/app/uploads/images/a7DZyC.png'
[REWRITE] Last Rule, stop!
This is the file, showing it exists:
Code:
[root@h1 lsws]# ll /usr/local/lsws/i.kltv.co/app/uploads/images/a7DZyC.png
-rw-r-xr-x 1 nobody nobody 65471 Mar  3 17:41 /usr/local/lsws/i.kltv.co/app/uploads/images/a7DZyC.png
I'm unsure why I receive a 404 instead of the file being displayed. Unsure what I have misunderstood as I'm trying to convert from my NGINX config.
 

Pong

Administrator
#2
maybe you should check the apache rewrite rules section on how to make them work.
https://httpd.apache.org/docs/2.4/rewrite/

Normally rewrite rule will be in .htaccess of a directory.

For example, if a image does not exist in /app/uploads/images/, rewrite to /app/uploads/images/a7DZyC.png.

then you can create a /app/uploads/images/.htaccess

Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule .* a7DZyC.png [L]
You will need to restart OLS everytime you make change to any .htacess in doc_root or subfolders
 
Top