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.
Related
I'm using WordPress for my business site and Laravel for Project management application.
Here is my directory structure.
public_html
-mainsite (my WordPress site is in this directory)
-work (Laravel Application is in this directory)
When user visits my primary domain (e.g. www.example.com) I'm redirecting the visitor to www.example.com/mainsite using following .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/mainsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mainsite/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ mainsite/index.php [L]
</IfModule>
My project management application which is located in 'work' directory is easily accessible with this URL
www.example.com/work/public
Now I want to allow users to access my project management application with this URL
(I want to remove 'public' from URL)-
www.example.com/work
Could you please help me to resolve this issue?
(It is easy to remove 'public' from URL when Laravel is installed in the root directory and I know how to do that)
This is not a duplicate question and here is the reason-
My Laravel installation is in subdirectory of my root directory and I'm also using different site (a WordPress site) for my base URL
Move Laravel to outside of public_html
Move content of Laravel's public folder to public_html/work
Put the following code in the \App\Providers\AppServiceProvider register():
$this->app->bind('path.public', function() {
return base_path('public_html/work');
});
I have read the doc from Yii2 official website to deploy yii2 into share host from this : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html, and about discussion on this : stackoverflow.
So, I decide to use sftp to upload the yii2 folder.
And this is the list of directory in my share host.
access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)
You know, because the share host can hold on domains untill 5 domains,
is it possible to upload yii2basic folder into public_html folder ?
So the result like this :
access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)
Because now, if I want to access my web, I have to write like this : mydomain.com/basic/public_html/index.php
I need like this :
mydomain.com/index.php
Please guide me.
Yes you can upload it inside the public_html folder but the only problem that I have been facing nowadays with yii2 basic app is the pretty URLs, you can clone or upload entire contents inside the public_html folder, what I did is as follows only the difference is I have a web folder instead of www
directory structure
public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web
public_html/.htaccess
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
public_html/web/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this works but in the URL it shows /web/index.php?r=site/index and as soon as I turn the prettyUrl on in the config file urlManager it would only show default index page and every link I try to open ends up on the home page view although the URL in the address bar is correct and urlManager parses the rules correctly, this is as far as I have gone.
If you don't mind bunch of Yii 2 folders in your root folder just place all basic template folders (except web) and files in the root folder. Then place the content of web folder in the public_html folder.
It should be something like:
access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets
I have been seeing several PHP online tutorials where they recommend that you have a public folder where you have your index.php and other views, css, js, etc and another folder (usually called app) where you have your classes and such. The idea is for the site to use the public folder as default so no one will be able to access the classes. The question is, once I upload the public and app folders to my server, how do I get the users to public/index.php when they type in mypage.com (without them having to type mypage.com/public).
You can use this .htaccess file, Place it in root folder of your website:
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /public/$1 [L]
I'm got some problem with Route in Laravel 4.2. Here is details:
I have an example route:
Route::get('users', function(){return 'some-thing'});
and the route still work normally at http:://localhost:8000/users.
However, when I create a subfolder inside public folder, its name is "users".
--public
--users
That link didn't work and return the folder index. I know that is a big sercurity problem.
How to fix it? Can you please help me?
I wouldn't say a huge security problem, if there is sensitive data in that folder, then it shouldn't be in "public". You could deny directory listings (assuming Apache virtualhost or .htaccess):
Options -Indexes
As in Laravel's (and most other frameworks') .htaccess file, it only uses the "Router" if the file or directory doesn't exist. This is common as shown below:
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Im trying to have a htacess file within my root folder so i can redirect the user to index.php file, if for example trying to access any file inside my root directory. I failed to do that. I have that file inside my root folder as i should, but when im trying to access files typing the names in the URL, i actually have access to the files. So the .htaccess file does not work.
I have to mention that im trying to do that locally, having wamp installed and using slim framework. I do not know if something mess with these.
The code that i have in my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have that file inside my root folder as i should, but when im trying to access files typing the names in the URL, i actually have access to the files
That means you want even the existing files not to be shown, and all requests should be redirected to index.php.
If that is the case then why do you have these conditions? Remove these
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
Those 2 conditions mean apply that redirect only if the requested url is niether a file nor a directory. No wonder for files that are actually present your redirect is not working. You told it so.