Welcome Guest, Not a member yet? Register   Sign In
Create CI4 project in sub folder
#1

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
Reply
#2

You will need to place the contents of the public folder inside codeigniter_project, and move the application elsewhere.
https://codeigniter.com/user_guide/gener..._apps.html
Reply
#3

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!!!!!
Reply
#4

(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/gener..._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.
Reply
#5

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

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.
Reply
#7

(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..._apps.html

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

(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..._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.
Reply
#9

(04-09-2020, 09:38 AM)jean5769 Wrote: 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


I might be late to answer this, Imma playing with CI4 recently, was stuck with the same problem and got the initial solution for the same, You do not have to change anything in the .htaccess file inside the public folder, all you have to do is create a new htaccess in root and paste the below code

Code:
#installpl is my subfolder
DirectoryIndex /installpl/public/index.php 
RewriteEngine on
RewriteBase /installpl
RewriteCond $1 !^(index\.php|images|assets|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./public/index.php/$1 [L,QSA]
Reply
#10

You need to change app/Config/Paths.php and also if you use spark you need to edit that file and change the path.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB