We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

LG trailing slash, HTTP 404 server response issues

Development and Programming

gregm's avatar
gregm
6 posts
16 years ago
gregm's avatar gregm

Hi,

I am trying to configure EE with LG (commercial) to do this:

  1. Add a trailing slash when there isn’t. Example: example.com/mypage >>301 redirect >> example.com/mypage/

  2. Generate a true 404 HTTP header response code on error pages. For now EE is returning a 200 response which is not ok at all.

  3. Return a 404 code directly, without redirecting with a trailing slash like above, when the page just doesn’t exist. Example: example.com/anynonexistingpage should return a 404 directly.

I’m trying to fix this for a long time now and can’t make it work as it should.

Can somebody help there?

Thanks

       
Danny T.'s avatar
Danny T.
426 posts
16 years ago
Danny T.'s avatar Danny T.

Dear Greg,

Have you looked into using the LG .htaccess generator? It should be able to solve your trailing slash issue and pretty much everyone else you said regarding the 404, etc.

       
gregm's avatar
gregm
6 posts
16 years ago
gregm's avatar gregm

I did install the LG .hataccess generator but it didn’t solve any of these issues. My .htaccess generator setting look like this:

# secure .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Dont list files in index pages
IndexIgnore *

# EE 404 page for missing pages
ErrorDocument 404 /index.php?/{ee:404}

# Simple 404 for missing files
<FilesMatch "(\.jpe?g|gif|png|bmp)$">
ErrorDocument 404 "File Not Found"
</FilesMatch>

RewriteEngine On

RewriteBase /

# remove the www
RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Remove index.php
# Uses the "include method"
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/({ee:template_groups}|{ee:pages}members|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]

It did remove the index.php as it should but the trailing slash, 404 pages returning a 200 code, and trailing slashes added after non existing pages remain.

Not sure what to do at this point.

       
Danny T.'s avatar
Danny T.
426 posts
16 years ago
Danny T.'s avatar Danny T.

Do you have a 404 template set in your template preferences? I’m not really the best one to answer these questions, but hopefully that helps you out.

       
Charles Boudinot's avatar
Charles Boudinot
87 posts
16 years ago
Charles Boudinot's avatar Charles Boudinot
Hi, I am trying to configure EE with LG (commercial) to do this: 1. Add a trailing slash when there isn’t. Example: example.com/mypage >>301 redirect >> example.com/mypage/ 2. Generate a true 404 HTTP header response code on error pages. For now EE is returning a 200 response which is not ok at all. 3. Return a 404 code directly, without redirecting with a trailing slash like above, when the page just doesn’t exist. Example: example.com/anynonexistingpage should return a 404 directly. I’m trying to fix this for a long time now and can’t make it work as it should. Can somebody help there? Thanks

I’m not sure if this will solve all your request, but, I corrected the issue by adding the following php to the top of my 404 template page. Now it returns the proper http headers rather than the code 200 OK.

<?php
global $TMPL, $OUT;
$OUT->out_type = '404';
$TMPL->template_type = '404';
?>

Be sure to allow php in the template preferences for your 404 template.

Hope that helps.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.