CodeIgniter Forums
Help, How to fix Codeigniter 404 response status with content on specific case - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Help, How to fix Codeigniter 404 response status with content on specific case (/thread-74042.html)



Help, How to fix Codeigniter 404 response status with content on specific case - juankav89 - 07-11-2019

I have a codeigniter project that return only in some case 404 header response, but with controller response.

Problem affect SEO score and page not load on Microsoft browsers.

Its Codeigniter 3.0.3 on cloudways server instance with apache PHP 5.6.  I try fix changed htaccess rules (i am newbie with that), and force header status 200 before execute load view code, but header status not change.

**CODE INFORMATION**

This its .htaccess::
```
<IfModule mod_rewrite.so>
   RewriteEngine On

   RewriteCond $1 !^(index\.php|images|stylesheets|javascript)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^(.*) /index.php/$1 [L]
   RewriteRule ^uploadify/.*$ - [PT]
   RewriteRule ^uploads/.*$ - [PT]

</IfModule>

<IfModule !mod_rewrite.so>
      ErrorDocument 404 /index.php
</IfModule>

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
```

routes.php fragment:
```php
$route['default_controller']        = 'apply'; // working
$route['apply-mortgage']            = 'apply/mortgage';  // not working
```

Same functions (index and mortgage) return a respective views with same code:
```
 $this->load->view();
```
I include MY_CONTROLLER too:
```php
class MY_Controller extends CI_Controller {
  public function _remap($method, $params = [])
  {
    if (method_exists($this, $method)) {
      $response = $this->$method(...$params);
      if ($response === null) {
        $response = Response::LAST();
      }
      if ($response instanceof stdClass || in_array(gettype($response), ['array', 'boolean', 'double', 'integer'])) {
        $response = Response::json($response);
      } elseif (is_string($response)) {
        $response = Response::html($response);
      }
      if ($response instanceof Response) {
        $response->output();
        exit;
      }
      if (isset($response)) return $response;
    }
    show_404();
  }
}
```

**BROWSER RESPONSE**

Actual response on browser console
header (network tab)
```
Confusedtatus: 404
Content-Type: text/html; charset=UTF-8
Pragma: no-cache
. . .
```
preview (network tab) return view response on controller function:
```
<!doctype html>
<html lang="en">
<head>
...
```

I need that header response status return 200


RE: Help, How to fix Codeigniter 404 response status with content on specific case - jreklund - 07-11-2019

You got show_404() in your controller. I should fix why it's returning 404 in the first place and it's incorrect to force status 200 for something that should be 404.


RE: Help, How to fix Codeigniter 404 response status with content on specific case - juankav89 - 07-25-2019

(07-11-2019, 11:37 PM)jreklund Wrote: You got show_404() in your controller. I should fix why it's returning 404 in the first place and it's incorrect to force status 200 for something that should be 404.

I remove 404 but not working. 

Problem its that controller->method exist. Not logic that response return correctly but header include 404.


RE: Help, How to fix Codeigniter 404 response status with content on specific case - InsiteFX - 07-26-2019

Did you look at the server log files to see what is going on?


RE: Help, How to fix Codeigniter 404 response status with content on specific case - juankav89 - 07-29-2019

These are server logs. (mmm Codeigniter nog generate anything with "log_threshold" on 4)

==> php-app.access.log <==
SOMEIP, 127.0.0.1 - [29/Jul/2019:13:03:59 +0000] "GET /index.php" 200 0 - 1169 8494 0.025 1835008 40.79% 0.00% "/apply-business-loans"

==> apache_phpstack-38010-80732-222717.cloudwaysapps.com.access.log <==
SOMEIP - - [29/Jul/2019:13:03:59 +0000] "GET /apply-business-loans HTTP/1.0" 404 38858 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"

==> nginx-app.status.log <==
status_code:404 SOMEIP [29/Jul/2019:13:03:59 +0000] GET /apply-business-loans HTTP/1.1


RE: Help, How to fix Codeigniter 404 response status with content on specific case - InsiteFX - 07-29-2019

log_message($level, $message)

Read the note at the bottom.


RE: Help, How to fix Codeigniter 404 response status with content on specific case - juankav89 - 09-04-2019

Log print all.