I'm developing a new website using codeigniter, this is my first codeigniter experience. I suspect that there is something not working with the 404 error, when I try to load a controller that does not exist, or a wrong function of an existing controller, I get back the standard webserver 404 error, and not the codeigniter one.
I did not touch the "404_override" option in the route config file.
Is it normal? I expect (but maybe I'm wrong) that in these cases the show_404() function is called.
Is your .htaccess file correctly set up?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
You have to setup an .htaccess file in order to have custom error pages working. Checkout the official documentation.
Codeigniter should be showing it's 404 page, unless you did not remove the index.php from the URI. In that case you can try to open another file without touching CodeIgniter. Take a look here to see how to remove index.php using .htaccess.
Update:
There seems to be a solution for ISS: ISAPI_Rewrite Lite (free, lite version of a commercial product). I found it here
Related
I just started a course of implementing MVC pattern using PHP and I think I'm experiencing a bug regarding friendly URL engine. The site I'm creating has the follow URL syntax: http://[site]/[controller]/[method]/[parameters] .
Until now it works in a very simple way: I access a controller and is printed on screen which controller is beeing accessed (printed by a method from controller's class). The problem is that when I access the URL http://cursophp/cliente (a real controller) it works and when I try an inexistent controller WAMP shows an error screen that informs that the page couldn't be found; but, when I try to access http://cursophp/produto (also a real controller), an 404 error from Apache is exhibited! And I also tried with other words like: produto1, produto2, product, product1 ("prod" prefix) and the same 404 error is exhibited!
Using Composer or including directly the controller file with "require" results in the same problem.
Is it a known bug or am I making a mistake?
htacess content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !f
RewriteCond %{REQUEST_FILENAME} !d
RewriteRule ^(.*)$ index.php/$1 [L]
Just adding more details:
When I try "pro" as controller's name:
When I try "prod" (or any word with "prod" prefix):
When I try "aaaa" (or any word, of any length, that doesn't correspond to a controller's name):
The problem is probably in function that checking the route. Try to debug on which line it's starting show the error. However, it's impossible to suggest you a specific way of solving this problem without providing more details
This PHP script is crappy, because it does not handle unknown controllers properly.
Instead it should respond with HTTP404, when the file to load cannot be located.
Generally speaking, you'd need to fix that in file Core.php.
I have a magento website, that is currently operating. Within a subfolder of this site, I have placed a 3rd party application that also has its own HTACCESS file to handle routing for its application.
When I access the folder http://example.com/somefolder the screen I expect shows up, but when I navigate to http://example.com/somefolder/newroute, I instead land on a magento 404 screen.
I have traced this to the magento htaccess file, in all cases, unlesss the path physically exists the rewriterule will always send the request to the index.php - this explains why Im getting there.
To fix this issue, I wrote a little rewriterule which I placed in the htaccess file of the magento store. The goal was to add an exception to any request that came through and contained any reference to my subfolder. The thought is now it should hit the path its supposed, then hit the htaccess file, and then route me to where IM supposed to be in this other application. Unfortunately it doesnt seem to work, after adding the rule I end up the same place - magento.
Here is what I've written:
RewriteRule ^(.*somefolder.*)$ $1 [L]
Im not sure what could be going wrong, as I think the approach seems pretty straight forward. Any ideas on how to remedy this situation?
Thanks.
Here is Your Simple Answer.Also Used By me on my site.
RewriteCond %{REQUEST_URI} !^/(yourfoldernameHERE)$
I have a Laravel 5 project with routes set up as well as a custom 404 page (mostly for missing/incorrect "pages").
So basically if I open any existing route I get the correct output and every other URL is showing the 404:
project.com/login - Fine, login page
project.com/ghdkfgl - 404
This looks clear and seems to be working as expected. So anything I add after the slash opens either an actual existing page or a 404 page.
Unless I put a 'index.php' anywhere in the URL. In this case, Laravel is executing the request for some reason like this:
project.com/jhdfkds/index.php/login - Opens the login page (the CSS and other resources are gone because of the paths but that's clear).
project.com/kfhjdsg/index.php/fkdhsg - Opens a 404 (but the CSS and other resources are not loaded too).
I'm sure both of these should open the 404 since there's no such routes in my project.
I also checked for the same behavior on the Laravel documentation website (I assume its built on Laravel).
http://laravel.com/docs/5.0 - Actual URL
http://laravel.com/aaa - A nice 404 page
http://laravel.com/aaa/index.php/docs/5.0 - Laravel documentation page again, same as the first one
What might be causing this? How can this be solved?
Why would Laravel even consider the 'index.php' in the middle of the URL?
Does this have anything to do with the .htaccess file? (I didn't edit it though)
The problem is inside the Symfony Request class and how it determines the base URL. Basically it assumes that if you have a request like aaa/index.php that your currently running script (named index.php) is inside the directory aaa takes aaa/index.php as base URL.
Later it will then be stripped from the actual request URI.
I fixed this unwanted behavior with a pull request that is currently under review. I will update this post as soon as it gets merged.
Same issue i was facing in laravel 3 when i was skipping public from url. then i have placed another htaccess file in public folder.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Within my wordpress site, I have a folder called projects. Whenever I access a page within the projects directory, the first response in the log is a 404. While this appears to have no impact on the page, it seems to mean that search engines aren't indexing these pages, as they first response they get from the page is a 404.
For example:
http://www.caseyrule.com/projects/sounds-of-sorting/
If you open the javascript console and look at the network log, you'll see that the first response is a 404 for the page itself, followed by all the assets of the page loading successful.
I tried adding a line to the .htaccess to exclude that directory from rewrites for the projects folder, but that didn't fix the problem.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(projects) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas what could be going on here?
Update: I've been doing some experiementing and it seem that the only pages on which I am seeing this error are pages that include wp-blog-header.php, in order to make use of the wordpress functions such as wp_nav_menu and get_search_form.
include dirname(__FILE__).'/../wordpress/wp-blog-header.php';
It is still not clear to me though why this would result in cause the first response from the page to be a 404.
Looking at your log shows that the http response with the 404 status code in the header is the same response that carries all the data.
This in turn show clearly that the 404 status code is not generated by the server because it didn't find the page, it is generated by some php code in wordpress.
You could look through the code to find the header() function, and the debug from there.
Anyway, looking at your website, I cannot reproduce the issue. Either you fixed it, or it was a temporary issue, probaly due to an incompatible plugin or similar.
With birgire's help, I figured this one out:
The fix was as simple as replacing:
include dirname(__FILE__).'/../wordpress/wp-blog-header.php';
with
include dirname(__FILE__).'/../wordpress/wp-load.php';
More information in this thread from wordpress.stackexchange.com
I'm writing my own url shortener. I'm done with everything such as creating short urls. But when I try to browse htt p://example.com/rtr93, I get a 404 error. But http://example.com/index.php/rtr93 works find and shows the relevant page (I'm not redirecting to a new url. I'm just getting the relevant record from database which has a column short_url).
I'm using PHP and syfmony 1.2 if that helps. I think I need to properly setup .htaccess file. But I don't know where to get started.
Something like this should work:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /index.php [L]
You may want to make the regex more specific if you're planning on hosting other things on the same domain.