Welcome Guest, Not a member yet? Register   Sign In
Every CodeIgniter page being returned falsely as 404, although displaying correct content
#1

[eluser]besson3c[/eluser]
This is pretty weird...

When you go to http://www.netmusician.org, you will see the correct content and the entire site behaves just fine from an end-user perspective, except Apache will log each page as a 404. All of the individual assets required by the page return correctly as 200, it's just the actual requested page that is returned as 404. If you go to http://www.netmusician.org/index.php it is logged as 200, which is an interesting clue. My .htaccess includes:

RewriteCond $1 !^(index\.php|system|wordpress|styles|js|nm_webkit|robots\.txt|favicon.ico)
RewriteRule ^(.*)$ /index.php/main/$1 [L]

However, I don't think this is the problem, as going directly to http://www.netmusician.org/index.php/main also generates the 404:

[myIP] - - [07/Mar/2010:04:17:01 -0500] "GET /index.php/main HTTP/1.1" 404 2273 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/533.2+ (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10"

Non CodeIgniter sites on the same server do not falsely return 404 errors such as this unless the page is actually a 404, this is definitely specific to my beloved CodeIgniter.


What sort of thing could be causing these false 404 errors? I'm pretty sure this problem is specific to the CI codebase based on my experimentation, I've tried all URI Protocol combinations in my site's config. Is there anything I ought to try or consider?

This is completely baffling and is affecting my Google search results.
#2

[eluser]tomcode[/eluser]
As a quick fix try in Your .htaccess :
Code:
RewriteRule ^(.*)$ /index.php?/main/$1 [L]

Hopefully this works.

Then You might dig deeper, why do You use /main ? If that's Your default controller You should have in Your .htaccess
Code:
RewriteRule ^(.*)$ /index.php/$1 [L] // again, You might need the ? sign

If it's not Your default controller, why not ?
#3

[eluser]besson3c[/eluser]
[quote author="tomcode" date="1267981778"]As a quick fix try in Your .htaccess :
Code:
RewriteRule ^(.*)$ /index.php?/main/$1 [L]

Hopefully this works.

Then You might dig deeper, why do You use /main ? If that's Your default controller You should have in Your .htaccess
Code:
RewriteRule ^(.*)$ /index.php/$1 [L] // again, You might need the ? sign

If it's not Your default controller, why not ?[/quote]


It is my default controller, but I don't want "main" to appear in my URLs, I use a single controller "main" for this entire site. I'll try the .htaccess suggestions and report back here, thanks *very* much for your help!
#4

[eluser]tomcode[/eluser]
If You don't want to have 'main' in Your URL, use _remap() in Your Controller together with routing :

Code:
$route['(:any)'] = "main/$1";

If You use more than one controller, do a forum seach for more detailed examples, here's one example
#5

[eluser]besson3c[/eluser]
[quote author="tomcode" date="1267981778"]As a quick fix try in Your .htaccess :
Code:
RewriteRule ^(.*)$ /index.php?/main/$1 [L]

Hopefully this works.

Then You might dig deeper, why do You use /main ? If that's Your default controller You should have in Your .htaccess
Code:
RewriteRule ^(.*)$ /index.php/$1 [L] // again, You might need the ? sign

If it's not Your default controller, why not ?[/quote]




That's really weird... The ? mark works on every page except for /blog, for some reason. /blog is just like the others, a CI driven page with a WordPress loop on it, although the WordPress stuff isn't even seen before the headers are returned. blog() is a function inside my main controller like the other pages...

What is this question mark doing and how is this working? Sending everything after index.php as a query string? Weird...

Thanks for your help, this is a big improvement!
#6

[eluser]tomcode[/eluser]
Quote:Sending everything after index.php as a query string? Weird…

That's how clean URL's work with one central entry point (index.php), the ? is required for certain server configurations, can't tell You more.


P.S.: Consider optimising Your pages, You're loading a lot of stuff ... especially for someone who offers his web dev services ...Wink
#7

[eluser]besson3c[/eluser]
[quote author="tomcode" date="1268007515"]
Quote:Sending everything after index.php as a query string? Weird…

That's how clean URL's work with one central entry point (index.php), the ? is required for certain server configurations, can't tell You more.


P.S.: Consider optimising Your pages, You're loading a lot of stuff ... especially for someone who offers his web dev services ...Wink[/quote]



Looking into the remap function now as per another poster's suggestion, unless you have a solution for /blog?


Stuff is optimized, what sorts of optimization do you feel is lacking? Perhaps some browsers don't cache 404 pages, which might be problem here...
#8

[eluser]tomcode[/eluser]
Your're loading more than 30 js files, more than 10 css files, the hidden contact form, I do not call that optimized
#9

[eluser]besson3c[/eluser]
[quote author="tomcode" date="1268006737"]If You don't want to have 'main' in Your URL, use _remap() in Your Controller together with routing :

Code:
$route['(:any)'] = "main/$1";

If You use more than one controller, do a forum seach for more detailed examples, here's one example[/quote]



Cool, this works and gets rid of my 404 errors, but I'm having a problem with my other routes in my routes.php file:

Code:
$route['(:any)'] = "main/$1";
$route['main/learnmore/:any/ajaxreload'] = "main/learnmorecontent";
$route['main/support/category/:any'] = "main/support";
$route['main/support/:any'] = "main/supportinner";
$route['main/searchsupport/:any'] = "main/searchsupport";
$route['main/searchblog/:any'] = "main/searchblog";
$route['main/:num/:num/:any'] = "main/blogpost";

is the first rule read and the others ignored? If you want to see this in action, this is available on http://dev1.netmusician.org
#10

[eluser]besson3c[/eluser]
[quote author="tomcode" date="1268008753"]Your're loading more than 30 js files, more than 10 css files, the hidden contact form, I do not call that optimized[/quote]


Many of those assets are loaded via YUI loader which loads them dynamically as needed after page load. This optimizes the load on pages where these assets aren't needed, but I'm noticing that several browsers don't cache this sort of YUI loaded content properly and/or know when to fetch a new copy, so I have mixed feelings about using it....




Theme © iAndrew 2016 - Forum software by © MyBB