Welcome Guest, Not a member yet? Register   Sign In
Error 404 on things after "/"
#1

Hi!
I had no idea, how to describe my problem in one line ;-) Basically, if I use an URL, i got a 404. Some examples:
First, https://domain works. It calls the basic controller and method. Fine. But then it begins: All called files like /dasboard.css ends up in a 404 error. If i try to call a controller eg https://domain/controller, it also ends in 404.
Sorry for that explanation, I hope you understand my problem :-)
Thank you
Reply
#2

Okay, I'm a little bit further.

My controllers are loading correctly now. I did it with this .htaccess (latest working version, but it works with less code too):

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]


But all other stuff, like images or CSS-File are loaded as controller too... Er error message is now "404 - File Not Found - Controller or its method is not found: \App\Controllers\Dashboard::template". "Dashboard" and "Template" are directorys where the CSS-file (in this case) is located.
Reply
#3

(This post was last modified: 08-09-2021, 12:57 AM by InsiteFX. Edit Reason: Fixed spelling )

i can't see why you would want to use a .css file in a url css is about how content is displayed and you quote a css file in the head of a php /html file.

But i'm guessing not using routing .

Let me give you an example :

Code:
$routes->get('pineapple','Login::login');

So if i put this url in browser address bar:

Code:
https://mydomain.com/pineapple

because that route is defined it invokes class "Login" and method "login" of the class.

In the class method is defined amongst other things what views to display

So the approach is to set up specific routes and then what i do is lastly have a route defined as a catch all; it looks for presence of the name of a file in views. if it finds it ,
it displays it. if it doesn't it displays a view saying page not found. A 404 basically is saying whats being asked for ca not be found
Reply
#4

Also make sure that your base_url in app/Config/App.php is set with an ending slash on the url /
What did you Try? What did you Get? What did you Expect?

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

Thanks so far!
What I mean is, that no CSS-File, even all other files, are not loading. Sorry for my english :-)
baseURL has a trailing slash. I try this three ways to check what is going on:
Code:
<link rel="stylesheet" href="<?= base_url('dashboard/template/xyz.css');?>">

<link rel="stylesheet" href="dashboard/template/xyz.css">

<link rel="stylesheet" href="/dashboard/template/xyz.css">
I check the network traffic (F12 > Network traffic) and see only 404 errors on all loaded files. If I go to "Answer", I can see the error, which I will call the "Oops"-Error :-) Happens sometimes :-)
The answer looks as every file, even in public folder, are loaded like a controller, Because "Dashboard" and "Template" in "Message" (line 4) are the first in directories in /public like in my HTML-markup above.
PHP Code:
{
 
"title""CodeIgniter\\Exceptions\\PageNotFoundException",
 
"type""CodeIgniter\\Exceptions\\PageNotFoundException",
 
"code"404,
 
"message""Controller or its method is not found: \\App\\Controllers\\Dashboard::template",
 
"file""/var/www/vhosts/[...]/vendor/codeigniter4/framework/system/CodeIgniter.php",
 
"line"992,
 
"trace": [
 {
 
"file""/var/www/vhosts/[...]/vendor/codeigniter4/framework/system/CodeIgniter.php",
 
"line"992,
 
"function""forPageNotFound",
 
"class""CodeIgniter\\Exceptions\\PageNotFoundException",
 
"type""::",
 
"args": [
 
"Controller or its method is not found: \\App\\Controllers\\Dashboard::template"
 
]
 },
 {
 
"file""/var/www/vhosts/[...]/vendor/codeigniter4/framework/system/CodeIgniter.php",
 
"line"353,
 
"function""display404errors",
 
"class""CodeIgniter\\CodeIgniter",
 
"type""->",
 
"args": [
 {}
 ]
 },
 {
 
"file""/var/www/vhosts/[...]/index.php",
 
"line"44,
 
"function""run",
 
"class""CodeIgniter\\CodeIgniter",
 
"type""->",
 
"args": []
 }
 ]

Reply
#6

Is there a local version of the site? If so, do you have these types of problems?
Reply
#7

(This post was last modified: 08-09-2021, 08:06 PM by wuuyun.)

first public is your webroot

if want include statics   <link rel="stylesheet" href="<?=base_url('dashboard/template/xyz.css');?>">
your css file path must be this :  public/dashboard/template/xyz.css
now <link rel="stylesheet" href="<?=base_url('dashboard/template/xyz.css');?>">
it work
Reply
#8

Despite all the information given by you suggests using xampp, as in the opening of the problem you informed: ""First, https://domain works. It calls the basic controller and method.", this led me to ask if there was a local site.
Assuming then that you are using xampp, allow me to suggest the following steps for solving the problem.
1 - in xampp/htdocs, create a folder, with the name you want, where all CI4 files will be moved;
2 - in xampp/apache/conf/extra, edit the httpd-vhosts.conf file which should look similar to the one below:
PHP Code:
# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias ??in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias ??www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost> 

you can remove # to enable the lines and make the necessary changes, but again let me suggest an example:
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ci-folder/public"
    ServerName localhost
    ErrorLog "logs/ci-folder-error.log"
</VirtualHost>

where: ci-folder is the name of the folder created in htdocs and where the files were moved to;
localhost must be informed in ServerName, because it works as an https certificate, browsers will recognize it as a "safe site", the alert "not secure" will not be displayed in the navigation bar;
finally, stop/start the apache server, most likely this will solve the problems.
Reply
#9

Thank you guys, it's solved.

Quote:your css file path must be this :  public/dashboard/template/xyz.css
That's it. But it seems, that you can use it without /public, if your .htaccess-file is configured to manage this. Maybe, my one was it, before I changed things here. This is just a private project and coding is not my job acctually, so I havn't a copy of the file, where it works without /public. Hmm.


Thank you for your help and best regards
Reply




Theme © iAndrew 2016 - Forum software by © MyBB