I have a file structure like this:
ROOT
|----app/
|----app/init.php
|----public/
|----public/index.php
|----public/img/
|----public/js/
|----.htaccess
The .htaccess
's rules will redirect all REQUEST_URI
to app/init.php
RewriteCond %{REQUEST_URI} !\.(css|js|ttf|woff|woff2|eot|otf|svg|png|jpg)$
RewriteCond public/%{REQUEST_FILENAME} !-f
RewriteCond public/%{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ app/init.php [NC,L,QSA]
Then app/init.php
will use require_once
to get the appropriate .html/.php
in the public
folder.
This works fine; all excluded file in .htaccess
will be called as such public/...
pattern of path in public/index.php
.
For examples:
- CSS
<link rel="stylesheet" href="public/css/layout.css">
- Image
<img src="public/img/abc.jpg" alt="">
However, I don't want to add public/
prefix on all the file I excluded in .htaccess
I tried adding
RewriteCond %{REQUEST_URI} \.(jpg)$
RewriteRule ^([^?]*)$ public/$1 [NC]
However, it does not work. More accurately, when I called like this img/abc.jpg
in public/index.php
file, it feeds back is 500 (Internal Server Error). I am guessing it is something wrong with the redirection, but I am not sure.
Question: How can I call css
or img
or etc.. those file without a prefix of public/
in the path?