so basically I have a link in my html domain.com/app/css/build/app-23471942834.css however on the server the file actually lives in /fs/current/public/css/build/app-23471942834.css. Is there a way to check if a file exists in a RewriteCondition? The problem is that I basically need the /css/build/app-23471942834.css part to check, without the /app. Is there a way to remove this in a condition?
So I need:
domain.com/app/loginto be rewritten to/fs/current/public/logindomain.com/app/build/css/app-123523.cssto be rewritten to/fs/current/public/build/css/app-123523.cssdomain.com/app/build/js/app-123523.jsto be rewritten to/fs/current/public/build/js/build/app-123523.css
I am using Laravel so within my public directory there is another .htaccess by default with this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Sorry, but I really suck at htaccess files. Thanks for your help.
What I got so far:
RewriteCond %{HTTP_HOST} ^(www.)?domain.de$ [NC]
RewriteCond %{DOCUMENT_ROOT}/fs/current/public/$1 -f
RewriteRule ^app/(.*)$ /fs/current/public/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?domain.de$ [NC]
RewriteRule ^app/(.*)$ /fs/current/public/index.php?/$1 [L]
SOLUTION:
I solved my issue like this:
RewriteCond %{HTTP_HOST} ^(www.)?domain.de$ [NC]
RewriteCond %{REQUEST_URI} \.(css|jpg|gif|png|js|svg)
RewriteRule ^app/(.+)$ /fs/current/public/$1 [L]
So all the rewrite only applies to css/jpg/gif/png/js/svg I think the issue I had before, was that the index.php file was rewritten by the script as well.
/css/build/app-23471942834.csspart to check"? Presumablyapp-23471942834.cssnever exists? Why do you need to check that the resource exists? Can't you just rewrite it if it matches the pattern? Or is this just an example of one such pattern and you have many different CSS and JS URLs/files like this? – MrWhite Jul 18 '16 at 13:42%{HTTP_HOST}check is unnecessary. – MrWhite Jul 18 '16 at 16:15