简体   繁体   中英

Access files outside public folder in Codeigniter 4

I am working on multi tenant application in CodeIgniter4 in which I have a folder on root of my domain that caters to specific tenant like http://example.com/test and http://example.com/test1
I have implemented the multitenant architecture by placing the contents of public folder in tenant specific folder (test and test1 in my example). each tenant having its own set of files (which are usually kept under public folder). Screenshot of current directory structure I need to store some common Javascript, css and images files accessible to all the tenants.

Add this to your public/.htaccess file to create a fallback for common files. If a request is made for /test/app.js , and the file does not exist, then this rule will try to serve /app.js instead.

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)/(.*\.(css|js|jpg|jpeg|png|ico|txt))$
RewriteRule (.*)/(.*\.(css|js|jpg|jpeg|png|ico|txt))$ /$2 [L]

Add this above the rewrite rule for index.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM