I am attempting to craft an .htaccess rule file for an Apache-hosted application which redirects all URI’s to a specific script, except if the URI references specific static resources.
One challenge challenge is I would like to collapse the URI so that the sub-folder is never referenced in the URI; a better way to illustrate is to show the file layout:
app/ ---|.htaccess ---|public/index.php ---|css/ ---|css/style.css ---|images/ ---|images/logo.png ---|js/ ---|js/main.js
I’d like to redirect every URI to the index.php in the public folder, except if it references a file in the css, images, or js sub-directory.
My working .htaccess is here:
Options All -Indexes RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC] RewriteRule ^ %1 [L,NE,R=302] RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]
And almost works, correctly redirecting all URI’s to the correct script, but I cannot craft rules that redirect the static resources i.e. the URI for the CSS should be /css/style.css (currently, /public/css/style.css works as expected).
I’ve tried modifying the .htaccess to require exact matches, but that doesn’t seem to do what I had hoped.
DPH-SG is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.