CodeIgniter Forums
Why CI4 Cannot Run in a Subdirectory? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: Why CI4 Cannot Run in a Subdirectory? (/thread-72478.html)



Why CI4 Cannot Run in a Subdirectory? - avicenna - 12-25-2018

Hi.

I've read somewhere that CI4 is not supposed to be run in a subdirectory (like Laravel?). What is the reason for this behavior?

In my previous experience, when I created a website for a client using CI3 or Wordpress, some clients usually want the staging version is uploaded to a subdomain subfolder (like example.com/staging/). What is the solution to this?

Thanks.


RE: Why CI4 Cannot Run in a Subdirectory? - dave friend - 12-25-2018

(12-25-2018, 04:58 AM)avicenna Wrote: Hi.

I've read somewhere that CI4 is not supposed to be run in a subdirectory (like Laravel?). What is the reason for this behavior?

In my previous experience, when I created a website for a client using CI3 or Wordpress, some clients usually want the staging version is uploaded to a subdomain (like example.com/staging/). What is the solution to this?

Thanks.

Perhaps you misread or the source was faulty. There is no "must be this way" file structure for CI4. This documentation describes how to relocate the application directory. Right below that is explained how to manage multiple apps which is what you describe as a staging version.


RE: Why CI4 Cannot Run in a Subdirectory? - ciadmin - 12-25-2018

If you access your app as xxx/myapp/public, then you are unnecessarily exposing the other folders in your app, eg. xxx/myapp/writable, unless you take care to configure things properly, eg with .htaccess files everywhere.

If you want to access your app as xxx/myapp, you might get away with a symbolic link of WEBROOT/myapp to WHEREVER_IT_REALLY_IS/public, but that is more work for you.

A better practice is to use subdomains, eg staging.xxx.com, rather than xxx.com/staging/public.

Another argument for mapping an app to a subdomain is for asset references. With a subdomain, '/images/abc.jpg' refers to the "images" folder inside your "public". With a directory mapping, then 'images/abc.jpg' would refer to 'public/images/abc.jpg' for the URL '', but to 'public/index.php/images/abc.jpg' if you aren't stripping index.php. It gets worse if you are using URI segments to pass parameters.

How does this differ from Laravel (or any of the other major frameworks)? I am curious Smile


RE: Why CI4 Cannot Run in a Subdirectory? - ciadmin - 12-25-2018

By the way, "example.com/staging" is NOT a subdomain, that refers to a subfolder. "staging.example.com" is a subdomain of "example.com"


RE: Why CI4 Cannot Run in a Subdirectory? - InsiteFX - 12-25-2018

And if you move the ./application and system folders you need to tell index.php
were they are located by changing there paths in index.php


RE: Why CI4 Cannot Run in a Subdirectory? - avicenna - 12-25-2018

(12-25-2018, 08:57 AM)dave friend Wrote:
(12-25-2018, 04:58 AM)avicenna Wrote: Hi.

I've read somewhere that CI4 is not supposed to be run in a subdirectory (like Laravel?). What is the reason for this behavior?

In my previous experience, when I created a website for a client using CI3 or Wordpress, some clients usually want the staging version is uploaded to a subdomain (like example.com/staging/). What is the solution to this?

Thanks.

Perhaps you misread or the source was faulty. There is no "must be this way" file structure for CI4.  This documentation describes how to relocate the application directory. Right below that is explained how to manage multiple apps which is what you describe as a staging version.

Maybe, "staging version" is wrong words for this. I mean, it is possible to run the application in a sub-folder (not subdomain)?


RE: Why CI4 Cannot Run in a Subdirectory? - avicenna - 12-25-2018

(12-25-2018, 09:15 AM)ciadmin Wrote: By the way, "example.com/staging" is NOT a subdomain, that refers to a subfolder. "staging.example.com" is a subdomain of "example.com"

Sorry, it was a typo, I mean sub-folder (example.com/staging), not a subdomain.

But it seems the easiest way is by just setting a subdomain.