Welcome Guest, Not a member yet? Register   Sign In
How to remove public/index.php from the URL
#1

Hello.

I have uploaded my demo application on production server, which uses cpanel, in a subdomain (if that is important)

If I visit my url
http://ea3.mydomain.net.be 
I get 403 Forbidden error

If I add public/index.php on the end of my URL:

http://ea3.mydomain.net.be/public/index.php
, I can see the page normally

My .env settings:
CI_ENVIRONMENT = production
app.baseURL = 'http://ea3.mydomain.net.be'

My app/Config/App.php is untouched, it is the same as I downloaded it from CodeIgniter site. I use the .env file as suggested on this forum.

Now, about my folder structure. As far as I can understand the CI 4 documentation only the public folder should be in the pubic_html folder, and everything else should be outside of it. But I have no such options:

I have my folder: ea3.mydomain.net.be and no other subfolders, so all folders from the default CI Installation are in that folder. My host use cpanel.

On the end: I make my homework. I searched here, and I found no useful advice on this topic. I make the research on Internet, and I found zillion copies of how to remove public and index.php from the URL in Codeigniter 4 and they are all SAME. Same code everywhere, and I highly doubt that those people have an idea what CodeIngiter is. What I think is that they are all after clicks, they find that someone write an article on that topic, they see no competitions, and they are trying to get clicks, since the code is SAME on all those pages.

So this forum in the only place where I am sure that I am asking the people who know what they are talking about. So, I am relying on your expertise. 

Cheers and happy holidays to all members of this community.

P.S. For some reason I was unable to remove the links. The remove link has been grayed I was unable to use it.
Reply
#2

(This post was last modified: 12-19-2020, 01:43 PM by InsiteFX.)

If index.php is suppose to be in public_html then you need to rename the public folder public_html

If you do that you also will need to edit the spark file and change the public to public_html.

There maybe other setting that also need to be changed, I have all my apps under public_html
but no sub-folders.
What did you Try? What did you Get? What did you Expect?

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

Thanks for your reply

I have no public_html folder at all. I have one folder (named as my domain) and that is the root folder. And inside I have all my files and folders as they has been downloaded from CodeIgniter. 

--mydomainname
  -.well-known
  -app
  -cgi-bin
  -public
  -system
  -writable
  .env 
  .robots.txt

And I am still getting that 403 Forbidden error. So, how should I change my folder structure, or my .env file to get rid of the error?
Reply
#4

(This post was last modified: 12-21-2020, 06:19 AM by includebeer.)

If your host gives you something like /home/username/domain.com/, put the content of the public folder in /home/username/domain.com/ and everything else in /home/username/

It seems like everybody is confused by the new way CI4 deal with the concept of public and private folders. The content of "public" goes in your public folder, whatever its name is, and everything else goes one level up, so it's not publicly accessible.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

(12-21-2020, 06:19 AM)includebeer Wrote: If your host gives you something like /home/username/domain.com/, put the content of the public folder in /home/username/domain.com/ and everything else in /home/username/

It seems like everybody is confused by the new way CI4 deal with the concept of public and private folders. The content of "public" goes in your public folder, whatever its name is, and everything else goes one level up, so it's not publicly accessible.

I appreciate the fact that you find time to answer my question. However, no I have no such luxury on this host. What I have is one folder: mydomain.be

And I have to find a solution that will work on all hosts, since I use CodeIgniter in all my projects, so I need to find a way around this obstacle, which will not compromise the security of the website - app.

Needles to say, exactly the fact that that all files should be outside of the root folder significantly increases the security, but how to find a solution that will work on all hosts is the question of 1 million $...

Hopefully some of the community will find the right answer.

Once again, thanks for your answer...
Reply
#6

In that case I would start looking for a new host. I have my hosting with.

WebHostingBuzz

I have been with them for over 10 years now because they have one of the best
support around. They will even make changes for you to make sure things work
the way you want them to.
What did you Try? What did you Get? What did you Expect?

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

(12-22-2020, 07:54 AM)t_5810 Wrote: And I have to find a solution that will work on all hosts, since I use CodeIgniter in all my projects, so I need to find a way around this obstacle, which will not compromise the security of the website - app.

Needles to say, exactly the fact that that all files should be outside of the root folder significantly increases the security, but how to find a solution that will work on all hosts is the question of 1 million $...

It's better to have most of the code outside the root folder, but if your host gives you no other choice, I'm sure you can make it work with everything in your public folder. Before CI4, a lot of people didn't bothered to move the application and system folders outside the root. You'll have to edit index.php so it can find your app folder: 

PHP Code:
<?php
// Location of the Paths config file.
// This is the line that might need to be changed, depending on your folder structure.
$pathsPath realpath(FCPATH '../app/Config/Paths.php');
// ^^^ Change this if you move your application folder 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB