Welcome Guest, Not a member yet? Register   Sign In
How do you deploy site with subfolder in baseURL
#1

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

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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 .
CMS CI4     I use Arch Linux by the way 

Reply
#4

(This post was last modified: 07-09-2023, 03:41 AM by luckmoshy.)

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]
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#5

Yes, subdomains (no subfolder) is recommended.

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

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

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

@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]
Reply
#9

(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
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB