Welcome Guest, Not a member yet? Register   Sign In
custom 404 and routing problems
#1

(This post was last modified: 04-13-2016, 05:31 PM by discotom. Edit Reason: clarification )

I use CodeIgniter.


I route certain urls to different files based on the structure of url using the routes.php file. Everything has been working fine.

However, a few months ago, i thought i would add a custom 404 page. I did and things appeared to be working fine.

HOWEVER, i have just realised that every page on my site (except the home page) gives a server response http status 404 error and yet displays to the human user the correct page. why is it setting a 404 status and not a 200 status??

I have no idea how that's happening but it's obviously a nightmare as i am now not indexed from all search engine listings!!! The only thing i can think of is that i did something when setting the custom 404 page which meant that every page regardless of whether found or not has a 404 status. incidentally, if i try to navigate to a page that doesn't exist, i get my Custom 404 error page. Domain is http://citylightstours.com


My routes.php file is:


Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|   example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|   http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
|   $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|   $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/

$route['default_controller'] = "content";
$route['en/(:num)/(:any)'] = "content/en/$1";
$route['de/(:num)/(:any)'] = "content/de/$1";
$route['es/(:num)/(:any)'] = "content/es/$1";
$route['it/(:num)/(:any)'] = "content/it/$1";
$route['ar/(:num)/(:any)'] = "content/ar/$1";
$route['404_override'] = '';


/* End of file routes.php */
/* Location: ./application/config/routes.php */


My .htaccess file is:



Code:
<IfModule mod_rewrite.c>
# Development
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

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]

# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------

<IfModule mod_setenvif.c>
 <IfModule mod_headers.c>
   BrowserMatch MSIE ie
   Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
 </IfModule>
</IfModule>

<IfModule mod_headers.c>
 Header append Vary User-Agent
</IfModule>


# ----------------------------------------------------------------------
# Webfont access
# ----------------------------------------------------------------------

<FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
 <IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>
</FilesMatch>

# ----------------------------------------------------------------------
# Proper MIME type for all files
# ----------------------------------------------------------------------

# audio
AddType audio/ogg                      oga ogg

# video
AddType video/ogg                      .ogv
AddType video/mp4                      .mp4
AddType video/webm                     .webm

# Proper svg serving. Required for svg webfonts on iPad
#   twitter.com/FontSquirrel/status/14855840545
AddType     image/svg+xml              svg svgz
AddEncoding gzip                       svgz

# webfonts                            
AddType application/vnd.ms-fontobject  eot
AddType font/truetype                  ttf
AddType font/opentype                  otf
AddType application/x-font-woff        woff

# assorted types                                      
AddType image/x-icon                   ico
AddType image/webp                     webp
AddType text/cache-manifest            appcache manifest
AddType text/x-component               htc
AddType application/x-chrome-extension crx
AddType application/x-xpinstall        xpi
AddType application/octet-stream       safariextz

# ----------------------------------------------------------------------
# gzip compression
# ----------------------------------------------------------------------

<IfModule mod_deflate.c>

<IfModule mod_setenvif.c>
 <IfModule mod_headers.c>
   SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s,?\s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
   RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
 </IfModule>
</IfModule>

<FilesMatch "^(?!.*\.ogg$|.*\.ogv$|.*\.mp4$).+" >

# html, txt, css, js, json, xml, htc:
<IfModule filter_module>
 FilterDeclare   COMPRESS
 FilterProvider  COMPRESS  DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
 FilterProvider  COMPRESS  DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
 FilterChain     COMPRESS
 FilterProtocol  COMPRESS  change=yes;byteranges=no
</IfModule>
</FilesMatch>

# webfonts and svg:
 <FilesMatch "\.(ttf|otf|eot|svg)$" >
   SetOutputFilter DEFLATE
 </FilesMatch>
</IfModule>

# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------

<IfModule mod_expires.c>
 ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
 ExpiresDefault                          "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
 ExpiresByType text/cache-manifest       "access plus 0 seconds"

# your document html
 ExpiresByType text/html                 "access plus 0 seconds"

# data
 ExpiresByType text/xml                  "access plus 0 seconds"
 ExpiresByType application/xml           "access plus 0 seconds"
 ExpiresByType application/json          "access plus 0 seconds"

# rss feed
 ExpiresByType application/rss+xml       "access plus 1 hour"

# favicon (cannot be renamed)
 ExpiresByType image/x-icon              "access plus 1 week"

# media: images, video, audio
 ExpiresByType image/gif                 "access plus 1 month"
 ExpiresByType image/png                 "access plus 1 month"
 ExpiresByType image/jpg                 "access plus 1 month"
 ExpiresByType image/jpeg                "access plus 1 month"
 ExpiresByType video/ogg                 "access plus 1 month"
 ExpiresByType audio/ogg                 "access plus 1 month"
 ExpiresByType video/mp4                 "access plus 1 month"
 ExpiresByType video/webm                "access plus 1 month"

# htc files  (css3pie)
 ExpiresByType text/x-component          "access plus 1 month"

# webfonts
 ExpiresByType font/truetype             "access plus 1 month"
 ExpiresByType font/opentype             "access plus 1 month"
 ExpiresByType application/x-font-woff   "access plus 1 month"
 ExpiresByType image/svg+xml             "access plus 1 month"
 ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# css and javascript
 ExpiresByType text/css                  "access plus 2 months"
 ExpiresByType application/javascript    "access plus 2 months"
 ExpiresByType text/javascript           "access plus 2 months"

 <IfModule mod_headers.c>
   Header append Cache-Control "public"
 </IfModule>

</IfModule>

# ----------------------------------------------------------------------
# ETag removal
# ----------------------------------------------------------------------

FileETag None

# ----------------------------------------------------------------------
# Stop screen flicker in IE on CSS rollovers
# ----------------------------------------------------------------------

# The following directives stop screen flicker in IE on CSS rollovers - in
# combination with the "ExpiresByType" rules for images (see above). If
# needed, un-comment the following rules.

# BrowserMatch "MSIE" brokenvary=1
# BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
# BrowserMatch "Opera" !brokenvary
# SetEnvIf brokenvary 1 force-no-vary

RewriteEngine On
RewriteCond %{HTTP_HOST} !^citylightstours\.com$ [NC]
RewriteRule ^(.*)$ http://citylightstours.com/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]


Can anyone help please?
Reply
#2

Can anyone help - is there any other code i should post??
Reply
#3

Have you found a solution yet? Because I visited your website, tried a few links and everything sends a 200 statuscode, instead I go for some random site, that doesn't exist. If this error still exists (maybe in development) I think we need some extract of your controller and maybe the error class to see how you implemented the errorpage.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB