I'm trying to rewrite multiple directories for my app using .htaccess
All requests are processed via the 'app.php' file in my 'Web' directory which works absolutely fine but I've got my assets (CSS/JS/Images) in the 'Assets' folder but I want to be able to access them by pointing to 'css/filename.css'. The 'Assets' folder is outside the 'Web' directory
If I try adding a anything to the root .htaccess telling the server rewrite requests with a '.css' or '.js' extension to the appropriate location in the 'Assets' folder, then the rewrite that sends all other requests to the 'app.php' file in the 'Web' directory stops working altogether.
Requests:
Code:
http://localhost/page -> /htdocs/Web/app.php
http://localhost/css/filename.css -> /htdocs/Assets/CSS/filename.css
http://localhost/js/filename.js -> /htdocs/Assets/JS/filename.js
Structure:
Code:
htdocs
- .htaccess
- Assets
-- CSS
--- file.css
-- Images
-- JS
- Web
-- .htaccess
-- app.php
/htdocs/.htaccess:
Code:
<IfModule mod_rewrite.c>
#CSS
RewriteCond %{REQUEST_URI} \.(css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^css/(.*) Assets/CSS/$1 [L]
RewriteRule .? - [S=2]
#Reroute to app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^$ Web/ [L]
RewriteRule (.*) Web/$1 [L]
</IfModule>
/htdocs/Web/.htaccess
Code:
<IfModule mod_rewrite.c>
DirectoryIndex app.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css)$
RewriteRule ^(.*)$ app.php?$1 [PT,L]
</IfModule>
Thank you very much for your help!