CodeIgniter Forums
Create CI4 project in sub folder - 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: Create CI4 project in sub folder (/thread-76042.html)



Create CI4 project in sub folder - jean5769 - 04-09-2020

Hi !  Smile

I did several research about this subject, but I didn't find a solution.

I have a a domain who contains several projects. For example, I have something like this : Each project has a new folder (it'is a website used for development experimentation).

Now, I have tried to create a CI4 project inside a folder, like my other projects. So I put my CI4 folder (with /public, /app, /writable, etc.) inside a folder like : I want to access my project from this URL, without the index.php and without the /public folder in the URL.

I think I need to create a .htaccess file at the root of the project to redirect to the /public folder (and to adapt the .htaccess file inside the /public folder), but I can't get it to work...

If I don't have a .htacces in my CI4 root folder, I have a 403 Forbidden message, and if I create a .htaccess file, I always have a 500 error.

Someone knows how to do that ?

Thanks a lot ! Big Grin


RE: Create CI4 project in sub folder - jreklund - 04-09-2020

You will need to place the contents of the public folder inside codeigniter_project, and move the application elsewhere.
https://codeigniter.com/user_guide/general/managing_apps.html


RE: Create CI4 project in sub folder - dodbda - 04-09-2020

I have the same situation here.

I create a CI4 app in localhost with WAMP and a new VirtualHost and works correctly.

But, I want to add this app in a subfolder: "C:\wamp64\www\test\app_one", where "app_one" is my project;

In "app_one" I add a .htaccess with following content for the redirect to /public


Code:
RewriteEngine On
RewriteBase /test/app_one

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]



When access "http://localhost/test/app_one/"  the error is generated:


Quote:404 - File Not Found
Controller or its method is not found: App\Controllers\Test::app_one


In .htaccess of /public have this:


Code:
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /



When remove # and change to RewriteBase /test/app_one  or RewriteBase /test/app_one/public  the same error is generated.


Can someone help me? Thanks!!!!!


RE: Create CI4 project in sub folder - jean5769 - 04-09-2020

(04-09-2020, 11:01 AM)jreklund Wrote: You will need to place the contents of the public folder inside codeigniter_project, and move the application elsewhere.
https://codeigniter.com/user_guide/general/managing_apps.html

Thank you for your answer.

I saw this solution but I don't want to change the structure of the project. I think there is a solution with .htaccess file but I didn't find it.

I want to easily move my project without change the structure.


RE: Create CI4 project in sub folder - jreklund - 04-10-2020

I'm afraid that I won't help you find such a solution, as it's incorrect and not recommended practice.


RE: Create CI4 project in sub folder - meta - 06-04-2020

I'm not sure if this is something you can 'fix' with htaccess. Well, sure there will be any workaround about this topic but I'm not sure if that's a good practice as well.

I'm new to migrating from 3.x to 4.x, and I'm willing to do it very badly, but I also have old projects like yours that keep me from migrating.

E.g., I have the following structure

-- applications
----- administration
----- frontend
-- admin
----- assets
----- index.php (this is for the administration app)
-- assets
-- uploads
-- system
-- .htaccess
-- index.php (this is for the frontend app)

I mean, how can I re-structure this kind of projects? I get it that the new style is to have the core outside the whole project and manage every application as a whole new project, which is fine. But I want to keep this structure as I showed above where I can place all those indexes into their own subfolders within the public folder.

-- applications
----- administration
----- frontend
-- public
----- admin
-------- assets
-------- .htaccess
-------- index.php (admin)
----- assets
----- index.php (this is for the administration app)
-- system

After experimenting with CI4 I couldn't correctly call to the sub-applications into their own 'index wrapper'. After I edit the Paths.php and each index.php assigning them their correct path, all I get is new production error. I tried fixing my namespaces (which has nothing to do since the Autoload.php already have the App namespace wildcard on the PSR-4 array)

Any guess my dear community?

Thank you in advance.


RE: Create CI4 project in sub folder - jean5769 - 06-04-2020

(06-04-2020, 03:56 PM)meta Wrote: I'm not sure if this is something you can 'fix' with htaccess. Well, sure there will be any workaround about this topic but I'm not sure if that's a good practice as well.

I'm new to migrating from 3.x to 4.x, and I'm willing to do it very badly, but I also have old projects like yours that keep me from migrating.

E.g., I have the following structure

-- applications
----- administration
----- frontend
-- admin
----- assets
----- index.php (this is for the administration app)
-- assets
-- uploads
-- system
-- .htaccess
-- index.php (this is for the frontend app)

I mean, how can I re-structure this kind of projects? I get it that the new style is to have the core outside the whole project and manage every application as a whole new project, which is fine. But I want to keep this structure as I showed above where I can place all those indexes into their own subfolders within the public folder.

-- applications
----- administration
----- frontend
-- public
----- admin
-------- assets
-------- .htaccess
-------- index.php (admin)
----- assets
----- index.php (this is for the administration app)
-- system

After experimenting with CI4 I couldn't correctly call to the sub-applications into their own 'index wrapper'. After I edit the Paths.php and each index.php assigning them their correct path, all I get is new production error. I tried fixing my namespaces (which has nothing to do since the Autoload.php already have the App namespace wildcard on the PSR-4 array)

Any guess my dear community?

Thank you in advance.

Hi,

Thank you for your answer. I understand your problem but I think you need to create your own topic. You don't have the same problem.

You need to manage multi application projects. I guess you have already seen the page? https://codeigniter4.github.io/userguide/general/managing_apps.html

Can you try to use subdomain like admin.website.com?


RE: Create CI4 project in sub folder - meta - 06-05-2020

(06-04-2020, 10:23 PM)jean5769 Wrote:
(06-04-2020, 03:56 PM)meta Wrote: I'm not sure if this is something you can 'fix' with htaccess. Well, sure there will be any workaround about this topic but I'm not sure if that's a good practice as well.

I'm new to migrating from 3.x to 4.x, and I'm willing to do it very badly, but I also have old projects like yours that keep me from migrating.

E.g., I have the following structure

-- applications
----- administration
----- frontend
-- admin
----- assets
----- index.php (this is for the administration app)
-- assets
-- uploads
-- system
-- .htaccess
-- index.php (this is for the frontend app)

I mean, how can I re-structure this kind of projects? I get it that the new style is to have the core outside the whole project and manage every application as a whole new project, which is fine. But I want to keep this structure as I showed above where I can place all those indexes into their own subfolders within the public folder.

-- applications
----- administration
----- frontend
-- public
----- admin
-------- assets
-------- .htaccess
-------- index.php (admin)
----- assets
----- index.php (this is for the administration app)
-- system

After experimenting with CI4 I couldn't correctly call to the sub-applications into their own 'index wrapper'. After I edit the Paths.php and each index.php assigning them their correct path, all I get is new production error. I tried fixing my namespaces (which has nothing to do since the Autoload.php already have the App namespace wildcard on the PSR-4 array)

Any guess my dear community?

Thank you in advance.

Hi,

Thank you for your answer. I understand your problem but I think you need to create your own topic. You don't have the same problem.

You need to manage multi application projects. I guess you have already seen the page? https://codeigniter4.github.io/userguide/general/managing_apps.html

Can you try to use subdomain like admin.website.com?

Hello.

Actually, it is the same issue. What you need is just to make those folders, insert the index.php with its own .htaccess each and point to the right app that might be laying within the very same domain (or anywhere accesible within your server). Your approach is even more accesible given you want to have every dependency folder independent on its own folder 'wrapper' let's call it. 

I have seen the documentation and followed every step I could find about this multi app project, but didn't find anything. I just find similarities in the process with your request and didn't want to start a new topic on that, considering that we might be pursuing the same solution.