ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Pages Load without correct URL

January 13, 2014 7:30pm

Subscribe [3]
  • #1 / Jan 13, 2014 7:30pm

    Galactus

    2 posts

    Hey all,

    I have a strange issue.

    if I type.. mysiteurl.com/<whatever> it loads the 404 error page that I setup

    however
    if i type
    mysiteurl.com/<existing-template group page>/<whatever>

    Loads
    mysiteurl.com/<existing-template group page>/  which shouldn’t since that page doesn’t exist.

    is it something to do with my ht access file??

    <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
    
            # Removes index.php from ExpressionEngine URLs
            RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
            RewriteCond %{REQUEST_URI} !/system/.* [NC]
            RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
            # Directs all EE web requests through the site index file
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php?/$1 [L]
    </IfModule>
  • #2 / Jan 15, 2014 7:08am

    Giraffentoast

    152 posts

    That’s no bug, but a feature. 😉

    Only the first segment (<existing-template group page>) returns an error, if no respective template group exists.

    If Segment 2 is set, EE checks for an existing template (<segment_1>/<segment2>) and displays that. If no such template exists, <segment1>/index is loaded (no error is returned).


    Why would EE do that?
    Take a news section for example. The URLs would be:

    /news/north-korea-declares-war/
    /news/nigeria-bans-same-sex-marriage/
    /news/neil-young-oil/

    Now, there are no templates in group news called ‘north-korea-declares-war’ or ‘neil-young-oil’. Those are just the URL titles of each news entry.

    This would not be possible if Segments 2, 3, 4… were required to have templates named after them.

  • #3 / Jan 16, 2014 9:21am

    Boyink!

    5011 posts

    Usually you would handle this by putting the following code in your index template of a template group:

    {if segment_2 !=""}
      {redirect="404"}
    {/if}

    This assumes you have created a specific template for 404 purposes and identified it as such under Global Template preferences.

    What it’s saying is that if the index template is loaded with an additional URL segment it’s probably EE rolling back to the index template after not finding anything else. This does also assume your index template is not mean to be loaded with additional URL segments.

    Additionally here is a great resource on 404’s in EE:
    http://joviawebstudio.com/index_ee.php/blog/guide_to_404_pages_with_expressionengine/

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases