Welcome Guest, Not a member yet? Register   Sign In
CI4 in a shared host subfolder
#1
Question 

Sorry, I suppose it's a very repeated question, but I'm locked with that problem :-(

I updated my CI4 application to my hosting at http://dimas.cat
- Uploaded code to public_html/esventplanr
- Changed $baseUrl in App.php to http://dimas.cat/eventplanr/
- Copied index.php and .htaccess from public_html/esventplanr/public to public_html/esventplanr
- In index.php, I updated $pathsConfig to FCPATH . 'app/Config/Paths.php';

As you can see, http://dimas.cat/eventplanr/ it's accessible, but all the assets aren't loaded. CI4 tries to find it at http://dimas.cat/eventplanr/ but they are at http://dimas.cat/eventplanr/public . If I change the $baseUrl to the public folder, the assets work ok, but not CI4 routing.

In the code I use <?=base_url('bootstrap/css/bootstrap.min.css')?> or <?=base_url().'bootstrap/css/bootstrap.min.css'?>

How can I solve it?

Thx!!
Reply
#2

Do you want to setup the site http://dimas.cat/eventplanr/ ?
or http://dimas.cat/ ?
Reply
#3

(This post was last modified: 06-13-2023, 07:14 PM by kenjis.)

(06-13-2023, 06:13 PM)dimas Wrote: In the code I use <?=base_url('bootstrap/css/bootstrap.min.css')?> or <?=base_url().'bootstrap/css/bootstrap.min.css'?>

Use <?=base_url('bootstrap/css/bootstrap.min.css')?>.
See https://codeigniter4.github.io/CodeIgnit...l#base_url
Reply
#4

(This post was last modified: 06-14-2023, 12:06 AM by dimas.)

(06-13-2023, 07:09 PM)kenjis Wrote: Do you want to setup the site http://dimas.cat/eventplanr/ ?
or http://dimas.cat/ ?

http://dimas.cat/eventplanr/

(06-13-2023, 07:12 PM)kenjis Wrote:
(06-13-2023, 06:13 PM)dimas Wrote: In the code I use <?=base_url('bootstrap/css/bootstrap.min.css')?> or <?=base_url().'bootstrap/css/bootstrap.min.css'?>

Use <?=base_url('bootstrap/css/bootstrap.min.css')?>.
See https://codeigniter4.github.io/CodeIgnit...l#base_url

The result is exactly the same. The URL generated is http://dimas.cat/eventplanr/bootstrap/cs...ap.min.css and the file is in http://dimas.cat/eventplanr/public/boots...ap.min.css

If I change the baseUrl from 'http://dimas.cat/eventplanr/' to 'http://dimas.cat/eventplanr/public' the assets are loaded ok, but the CI routing not. And I don't want to see public/ in the url.
Reply
#5

(This post was last modified: 06-14-2023, 01:28 AM by kenjis.)

This is the case for http://dimas.cat/
https://forum.codeigniter.com/showthread.php?tid=76779

You want http://dimas.cat/eventplanr/,
so make the eventplanr folder in public_html, and put all the following files into it.
Code:
dimas.cat.eventplanr/ (create a folder with any name you like)
        app/
        system/
        writable/
        tests/
        ...
public_html/
    eventplanr/
        robots.txt
        index.php
        favicon.ico
        .htaccess

And fix the path in index.php:
PHP Code:
// Load our paths config file
// This is the line that might need to be changed, depending on your folder structure.
require FCPATH '../../dimas.cat.eventplanr/app/Config/Paths.php';
// ^^^ Change this line if you move your application folder 
Reply
#6

Navigate to http://dimas.cat/eventplanr/img/logo-192x192.png , you see "Can't find a route for 'get: /img/logo-192x192.png'. "
So your .htaccess config is something wrong.
All requests are routed to CI4 and the web server cannot serve images files.
Reply
#7

(06-14-2023, 01:34 AM)kenjis Wrote: Navigate to http://dimas.cat/eventplanr/img/logo-192x192.png , you see "Can't find a route for 'get: /img/logo-192x192.png'. "
Exact, but if you go to http://dimas.cat/eventplanr/public/img/logo-192x192.png it works. How can I redirect it?

(06-14-2023, 01:34 AM)kenjis Wrote: So your .htaccess config is something wrong.
All requests are routed to CI4 and the web server cannot serve images files.
This is my http://dimas.cat/eventplanr/.htaccess , is it wrong?

Code:
# Disable directory browsing
Options -Indexes

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Hide index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
    ServerSignature Off
# Disable server signature end
Reply
#8

Oh, your img folder locates in wrong place.
It should be:
Code:
dimas.cat.eventplanr/ (create a folder with any name you like)
        app/
        system/
        writable/
        tests/
        ...
public_html/
    eventplanr/
        img/    // Here
        robots.txt
        index.php
        favicon.ico
        .htaccess
Reply
#9

Thx @kenjis !! Now I understand. It worked!! ?

(06-14-2023, 03:28 PM)kenjis Wrote: Oh, your img folder locates in wrong place.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB