Results 1 to 6 of 6

Thread: 404 Error Page Behavior Contao 2.9.4

  1. #1
    User
    Join Date
    09-08-09.
    Location
    Snellville, GA
    Posts
    194

    Default 404 Error Page Behavior Contao 2.9.4

    Good morning!

    I've been trying to modify the 404 page in Contao 2.9.4 to get it to behave consistently, and I'm running into what appears to be a logic error.

    I've followed the guidance on the different threads for 404 pages, and through experimentation I've found these issues:

    1. The .htaccess file has to be modified on a Linux/Apache server in order for the 404 to work. If you just follow the instructions in the User Guide, by creating a 404 document it DOES NOT work without editing the .htaccess file.

    2. It seems that the call to the 404 file in the .htaccess file has to be placed ABOVE the line "<IfModule mod_deflate.c>" which is the first line of the Contao .htaccess code, as in:

    #
    # Uncomment the following lines to set the Error Documents.
    ##
    #ErrorDocument 403 http://www.openjlabs.com/403.html
    ErrorDocument 404 http://www.somedomainname.com/page-not-found.html

    <IfModule mod_deflate.c>

    3. If the wrong page called in a browser has any of these extensions, as in

    http://www.somedomainname.com/wrong-page
    http://www.somedomainname.com/wrong-page.htm
    http://www.somedomainname.com/wrong-page.php

    The 404 error page loads correctly.

    4. If the wrong page called has an extension of ".html" as in:

    http://www.somedomainname.com/wrong-page.html

    The error page fails to load.

    5. If I just turn off all of the 404 page setup and the .htaccess calls, then the cpanel server side 404 error page "Not Found" seems to load consistently for .php, .htm, no extension, although if the extension is ".html" a blank white page "Page not found" appears which I believe is a Contao error file. Right now I'm thinking that the issue involves the page alias function causing the conflict and that so far, only the server side page loads consistently for any page that does not exist or is misstyped with the .html extension.

    It seems like this topic was first addressed in a 2007 thread, and I'm just wondering if there are any thoughts as to how to get a styled Contao 404 page to load consistently regardless of the extension?

    Ernest McDermon
    Snellville, GA

  2. #2
    Community-Moderator xchs's Avatar
    Join Date
    06-19-09.
    Posts
    1,287

    Default Re: 404 Error Page Behavior Contao 2.9.4

    Hi,

    I would suggest calling Contao's Error pages by mapping these events to the script "index.php", i.e. with the following lines in your ".htaccess" (inserted after the license notice):
    Code:
    ErrorDocument 403 /index.php
    ErrorDocument 404 /index.php
    That said, all these wrong URLs are then handled correctly by Contao:

    http://www.example.com/wrong-alias.html
    http://www.example.com/wrong-alias.htm
    http://www.example.com/wrong-alias.php
    http://www.example.com/wrong-alias
    Contao Community Moderator
    → Support options

  3. #3
    User
    Join Date
    09-08-09.
    Location
    Snellville, GA
    Posts
    194

    Default Re: 404 Error Page Behavior Contao 2.9.4

    Thanks for the input, but that solution does NOT work, and it does NOT seem to track the documentation on how to set up a 403/404 page in the Contao system. I've tried multiple combinations of the call for the .htaccess file.

    Anybody else got a solution to this issue that works consistently? I can get it working as I described in my first post in this thread, but when I try a wrong page with the .html extension it goes back to the server standard "Page not found".

    My hypothesis is still that this is either a documentation issue in Contao, or more likely a logic error in how the system handles 404 calls with a .html extension. If I simply remove the Contao 404 routine, I get a blank white 404 page with the words "Page not found".

    Any suggestions or advice is appreciated!

    Ernest McDermon
    Snellville, GA

  4. #4
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: 404 Error Page Behavior Contao 2.9.4

    Hey Ernest,

    Try commenting out all of the 404 error page rules you added yourself, and instead change the very last RewriteRule (where it rewrites everything to index.php) to this:

    Code:
    RewriteRule .* index.php [L]
    And make sure there's nothing (aside from comments) between it and the 2 RewriteCond lines above it. This is normally the case, but make sure you didn't add anything.

    When combined, we're saying "rewrite everything that isn't an ACTUAL folder or file to index.php". And unlike the default rule, we're ignoring the file extension.

    Then make sure your "URL Suffix" settings have the extension you actually want to use.

    I use folder-style URLs over here, so I have the above rule and "/" is my URL suffix. And I have a little help from the folderurl extension to add subfolders (and that other one that adds them automagically).

    So this setup works for me -- I can enter literally anything that doesn't exist and it will send me to the 404 page. Let me know if this does for you too.

    I'm not sure why the above rule isn't the default one -- I'm sure there's a very good reason I just don't know what that is.
    Brian

  5. #5
    User
    Join Date
    09-08-09.
    Location
    Snellville, GA
    Posts
    194

    Default Re: 404 Error Page Behavior Contao 2.9.4

    I appreciate the input, that did not help either on my server. With the exception of a page that has a .html extension, here is what is working on the site for me at this time:

    1. Right below the copyright in the .htaccess file, I've added these lines:

    #
    # Uncomment the following lines to set the Error Documents.
    ##
    ErrorDocument 404 http://www.reeveassociates.com/page-not-found.html

    2. Right before the last line on the .htaccess file, I've left the default setting as in

    RewriteRule .*\.html$ index.php [L]

    </IfModule>

    3. In the site structure, I've created just under the domain root a "404" page with the name of "404" and a page alias of "404". It forwards to a "regular" page "Page Not Found" with the alias "page-not-found". There is a message on the page that indicates a 404 error.

    4. This setup works for most page extensions and loads the styled "page-not-found.html" page. If the extension is ".html", a blank page appears that says "Page not found".

    That's as far as I can take this issue, thanks for the input, if anybody else has any ideas about this, let me know.

    Ernest McDermon
    Snellville, GA

  6. #6
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: 404 Error Page Behavior Contao 2.9.4

    Sorry you couldn't get it working, Ernest.

    But honestly, it kind of sounds like something specific to your setup, rather than something with Contao. Because if you leave the rule as you have it in #2, if anything I'd think ONLY the .html pages should work, not the other way around.

    How are you redirecting FROM Contao's 404 page TO the actual error page? And is the actual error page a physical .HTML file? If so, are the following rules DIRECTLY ABOVE the rule you show in #2?
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Only comments can go in between
    RewriteRule .*\.html$ index.php [L]
    That's really important, because that's where it tells the server not to rewrite anything that's a physical file. Without these rules even URLs to files that exist will get filtered through Contao instead.

    This might be what is happening:

    1. You enter a URL that doesn't exist with a '.html' extension.
    2. Since your specific RewriteRule instructs Contao to ONLY handle .html files, it kicks in only for this use case. Others are handled directly by your ErrorDocument rule, so they're not affected.
    3. Contao can't find that page, so it sends you to the "404" page.
    4. That "404" page redirects to a physical page called "page-not-found.html".
    5. But if those above 2 RewriteCond's don't exist, Contao intercepts that URL too.
    6. Contao sees the alias "page-not-found".
    7. It looks but can't find a page with that alias in the system so it routes you to the "404" page.
    8. But then that just redirects back to "page-not-found" and the process starts over again, creating a loop.

    Maybe Contao is smart enough to spot the loop and at some point simply says "screw it", and sends you to that blank page.

    Worth asking -- for your .htaccess file, did you start with the one that ships with Contao (and maybe make any changes you need to that)?

    Also, did you start with the one that ships with your specific version? I noticed a big difference in the rules between 2.8 and 2.9, so if you did an upgrade, or you grabbed one from an older install, you may want to take a look at that.

    The reason I suggested my setup in the previous post is, if you do that then Contao will handle ALL 404 requests, and you can manage your 404 page content directly in the backend -- no need for a separate physical 404 file.
    Brian

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •