Redirect css (assets) with htaccess
I want to redirect my css files with htaccess, because the entire path is long.
I try this – index.php:
And this in my .htaccess
RewriteRule ^css/(.*)$ /app/view/templates/default/frontend/css/$1 [NC,L]
But, the CSS was not loaded.
GET http://localhost/css/styles.css 404 (Not Found)
Without a virtualhost
Direct Access: http://localhost/test
Apache Directory (Document Root):
/home/patrick/workspace/ = http://localhost
My “problem” (test) folder
/home/patrick/workspace/test/ = http://localhost/test
Inside /test folder
CSS path (inside test folder)
So, I want:
And then, redirect (call) the correct url, like that:
I try that but doesn’t work:
RewriteRule ^/css/(.*)$ /app/themes/default/css/$1 [NC,L]
1) I do not want create a VirtualHost/Alias for that URL.
My problem is about:
2) I can’t put a .htaccess in my DocumentRoot directory of apache
Why? Because is my development machine and I have a lot folders inside root. For example:
All items above is a folder in my workspace, and each folder is about different things, so, I don’t want to put .htaccess in root, UNLESS it really needed.
You don’t want that leading slash in your rule’s pattern.
RewriteRule‘s that are in the htaccess file will have the leading slash stripped off before applying the rule:
RewriteRule ^css/(.*)$ /app/themes/default/css/$1 [NC,L]
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Ebook Reviews
- PES Matches, Skills & News