Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 692 posts 1068 karma points
    Mar 15, 2015 @ 15:48
    Simon
    0

    Search listing no results should show 404 error status code.

    Hi all,

    How can accomplish that when the ezSearch find that no results were found, output a 404 error status code (Not Found)?

    Thank you in advance.

    Kind Regards

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 15, 2015 @ 18:20
    Dennis Aaen
    100

    Hi Simon,

    I think you can do it like this:

    First you need to find these lines in the ezSearch.cshtml. probably in line 285

    @helper RenderNoResults(SearchViewModel model){

        <div class="ezsearch-no-results">
            <p>@FormatHtml(GetDictionaryValue("[ezSearch] No Results", "No results found for search term <strong>{0}</strong>."), model.SearchTerm)</p>
            }
           
        </div>
    }

    To these lines of code you need to add Response.StatusCode = 404; so the final code will look like this

    Hope this does what you are after.

    @helper RenderNoResults(SearchViewModel model){
       
    <div class="ezsearch-no-results">
            <p>@FormatHtml(GetDictionaryValue("[ezSearch] No Results", "No results found for search term <strong>{0}</strong>."), model.SearchTerm)</p>
          
                @{
                    Response.StatusCode = 404;
                
                }   
            }
           
        </div>
    }

    /Dennis    

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 15, 2015 @ 19:06
    Jan Skovgaard
    0

    Hi Simon

    May I ask why you want to show a 404 if a search result is not found?

    Wouldn't it be nicer to track 0 results using Google Analytics and then figure out what people are searching for, which does not show any results? This can be really valuable knowledge and be an important part for optimizing content and SEO etc.

    Just my 2 cents :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft