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.

incorrect URL and 404 redirect

June 22, 2009 3:21pm

Subscribe [3]
  • #1 / Jun 22, 2009 3:21pm

    MarcinM

    17 posts

    Hi,

    I’m trying to use this metod to handle incorrect URLs, but can’t get it to work correctly.
    The situation is:
    http://www.domain.com/hotels/paris/ritz_hotel
    template group: hotels
    Then I got index template with a list of cities and separate template for each city that’s doing two things - if no hotel name in segment_3, then it shows list of all hotels in the city, if the hotel name is in segment_3, then it shows the hotel details.
    Now, I want to get 404 every time someone will put incorrect URL.
    For the index, I put:

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

    and it works fine (all the http://www.domain.com/hotels/parisasdkhagskdjh are redirected to 404).
    For the city-template I did:

    {if segment_3==""}
        Hotels in {segment_3}:
        1)
        2)
    {if:elseif segment_3!="" AND segment_4!=""}
      {redirect="404"}
    {if:elseif segment_3!=""}
        {exp:weblog:entries weblog="hotels" limit="1" dynamic="on" require_entry="yes"}
            {if no_results}
                {redirect="404"}
            {/if}
            
        Hotel: {title}
        {body}
        {/exp:weblog:entries}
    {/if}

    and the problem is that when URL is http://www.domain.com/hotels/paris/ it doing no_results redirect from 3rd if ... but shouldnt :(
    Am I missing something? Could you please, help me with that?
    EE 1.6.7 Build:  20090515

  • #2 / Jun 23, 2009 8:19am

    MarcinM

    17 posts

    I did some template debug and test with the conditionals and it looks like even when segment_3 is not set EE parse the exp:weblog:entries tag inside if that - in my opinion - should be passed. Now, during the parse there is no results of the exp:weblog:entries (because segment_3 is not set) and that’s why EE do redirect.

    Whet I remove require_entry=“yes” from the ee tag city level with hotels list works fine, but I can’t get 404 redirection for incorrect segment_3 (hotel name) because EE gets some other result to be show.

    Is there any way out from this situation?

    Is it normal EE behaviore that it parse all the exp tags in template first, and thet it do conditionals? I’m confiused 😖

  • #3 / Jul 16, 2009 6:05am

    chpops

    33 posts

    I have got the exact same problem - anyone any ideas?

  • #4 / Nov 11, 2009 8:32pm

    keola

    8 posts

    Bump

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

ExpressionEngine News!

#eecms, #events, #releases