CodeIgniter Forums
How do you deploy site with subfolder in baseURL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: How do you deploy site with subfolder in baseURL (/showthread.php?tid=88021)

Pages: 1 2


How do you deploy site with subfolder in baseURL - kenjis - 07-07-2023

I have proposed to add .htaccess to project root.
https://github.com/codeigniter4/CodeIgniter4/pull/7676

How do you deploy a site like http://example.com/myroject/ ?


RE: How do you deploy site with subfolder in baseURL - InsiteFX - 07-07-2023

This should be added to the CodeIgniter 4 Users Guide.

There are to many different server setups out there to be able to handle all of them.


RE: How do you deploy site with subfolder in baseURL - captain-sensible - 07-08-2023

subdomains is the approach i use ; one advantage is that you can host several sites for the same cost as hosting for one domain, if your hosting allows/has capability.

First thing is you need to edit your domain DNS to point at your hosting in order to have capability of your hosting receiving it. I do that via my "managing domains" management on hosting .

I add a new domain to my hosting .Next via cPanel i go to subdomains /add on domains ,i simply point the document route to domain.org/public

Ci4 as it is works for me without any further modification .


RE: How do you deploy site with subfolder in baseURL - luckmoshy - 07-09-2023

of course, this is what has been thought to come it will be a great task so but there is also one issue for the shared apps here !!


just look at here how you learn,......I put in the document root...
Code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]



RE: How do you deploy site with subfolder in baseURL - kenjis - 07-09-2023

Yes, subdomains (no subfolder) is recommended.

Also, the user guide does not provide any instructions on how to deploy with subfolder.


RE: How do you deploy site with subfolder in baseURL - kenjis - 07-11-2023

I sent a PR to update the user guide.
https://github.com/codeigniter4/CodeIgniter4/pull/7680
Reviews are welcome!


RE: How do you deploy site with subfolder in baseURL - kenjis - 07-24-2023

Can someone review the docs?
https://github.com/codeigniter4/CodeIgniter4/pull/7680


RE: How do you deploy site with subfolder in baseURL - kenjis - 07-24-2023

@luckmoshy What is the one issue?

Do you recommend (2) than (1)? What's better?

(1)
Code:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

(2)
Code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]



RE: How do you deploy site with subfolder in baseURL - luckmoshy - 07-24-2023

(07-24-2023, 06:09 PM)kenjis Wrote: @luckmoshy What is the one issue?

Do you recommend (2) than (1)? What's better?

(1)
Code:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

(2)
Code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]



Code:
# This Check if the original request contains "/public/" (case-insensitive)
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
This RewriteCond captures the part of the original request that comes after "/public/" and stores it in %1. The [NC] flag makes the condition case-insensitive.

Code:
# This Check If the request does not already start with "/public/", add it to the beginning
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

This RewriteRule checks if the request doesn't start with "/public/". If true, it internally rewrites the request to the "public/" subdirectory, effectively adding it to the beginning of the URL. The [L] flag stops further processing of other rules, and [NC] makes the match case-insensitive.

so I recommend 2


RE: How do you deploy site with subfolder in baseURL - kenjis - 07-26-2023

I tried @luckmoshy 's config. I put .htaccess in the project root (myproject/.htaccess) folder:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
    RewriteRule ^ %1 [L,NE,R=302]
    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

When I navigate to http://localhost:8888/myproject/, I see the Welcome page.

And when I navigate to http://localhost:8888/myproject/public/, I also see the Welcome page.
There is the default .htaccess in myproject/public/. So it seems it is used and myproject/.htaccess does not used.