Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

.htaccess redirect normally for static folder

I have a .htaccess file that redirects every requests to ./core/index.php. But for static files which are in ./node_modules/ and ./assets/ folders, I want to enable normal redirect for them.

So,

  1. if request: url/whatever/page/ -> redirect to: core/index.php
  2. if request: url/assets/image/file.png -> get: assets/image/file.png
  3. if request: url/node_modules/css/file.css -> get: node_modules/css/file.css

My current code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ core/index.php [L,QSA]

>Solution :

I am not really sure what you mean by "I want to enable normal redirect for them" … What you actually show as examples looks to me as if you do not want any rewriting or redirection to get applied at all for those two base paths. If so, then there are two alternatives for this:

Either use conditions:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/assets/
RewriteCond %{REQUEST_URI} !^/node_modules/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ core/index.php [L,QSA]

Or explicit exceptions:

RewriteEngine On
RewriteRule ^/?assets/ - [END]
RewriteRule ^/?node_modules/ - [END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ core/index.php [L,QSA]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading