• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help, How to fix Codeigniter 404 response status with content on specific case

#1
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
Reply

#2
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.