Advertisement:

Author Topic: Solution for 404 http header on empty categories/locations  (Read 6331 times)

teseo

  • Hero Member
  • *****
  • Posts: 6169
Solution for 404 http header on empty categories/locations
« on: March 11, 2015, 09:38:58 pm »
Hi,

Just found a neat way to send a nice 200 Ok when there are no search results (we want search engines indexing that page anyway), with no modification in core files.

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

Code: [Select]
<?php
function cust_avoid_false_404() {    
    if (!
Search::newInstance()->count()) header('HTTP/1.1 200 Ok'); 
}

osc_add_hook("after_search""cust_avoid_false_404" );
?>


Regards

itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: Solution for 404 http header on empty categories/locations
« Reply #1 on: March 12, 2015, 12:57:02 pm »
This is one mod that was badly needed. Awesome teseo....as always...Thank You
« Last Edit: March 12, 2015, 01:08:25 pm by itcafeonline »

itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: Solution for 404 http header on empty categories/locations
« Reply #2 on: March 19, 2015, 12:49:26 pm »
Hi teseo, I have been watching the soft 404's on web masters. They seem to have NOT gone down. They have remained the same. Will track more and let you know.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Solution for 404 http header on empty categories/locations
« Reply #3 on: March 19, 2015, 07:28:59 pm »
Hi,

This method is working, test any of those Webmasters URL's here:

http://httpstatus.io/

to see a 200 OK with no redirection.

Probably those were indexed before you made this modification. You'd need to ensure that Google re-index your whole site or mark those as errors (on Google side), so they should try again.

Regards

Aficionado

  • Guest
Re: Solution for 404 http header on empty categories/locations
« Reply #4 on: March 20, 2015, 09:27:11 am »
Nice change, thanks TESEO.

Especially on multi-country as subdomains mode this is needed to avoid a HUGE ammount of 404.

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: Solution for 404 http header on empty categories/locations
« Reply #5 on: March 20, 2015, 04:27:24 pm »
maybe this is better....
header response 200 ok status header('HTTP/1.1 200 Ok')
and put in meta ="noindex, follow" for empty pages!

!

p206ab

  • Sr. Member
  • ****
  • Posts: 343
Re: Solution for 404 http header on empty categories/locations
« Reply #6 on: May 31, 2015, 09:31:21 pm »
Awesome, been wondering about this empty categories noindexing problem for a while now.. thanks Teseo!  ;)

serjuc11111, why noindex,follow?
« Last Edit: May 31, 2015, 09:45:15 pm by p206ab »

Aficionado

  • Guest
Re: Solution for 404 http header on empty categories/locations
« Reply #7 on: June 09, 2015, 03:06:17 pm »
Just found out that Bender and some other bended-based themes, null empty cat/subcats with http: #

And that function above doesn't work any more.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Solution for 404 http header on empty categories/locations
« Reply #8 on: June 09, 2015, 03:46:01 pm »
Hi,

Really nothing to do with this matter, in Bender there's no link to another page if the category is empty, just "#". If you want to change this behaviour you need to alter bender/functions.php:

1.-

Code: [Select]
                    <?php } else { ?>
                    <a class="category <?php echo $_slug?>" href="#"><?php echo $_name ?></a> <span>(<?php echo $_total_items ?>)</span>

to:

Code: [Select]
                    <?php } else { ?>
                    <a class="category <?php echo $_slug?>" href="<?php echo $_url?>"><?php echo $_name ?></a> <span>(<?php echo $_total_items ?>)</span>

2.- A few lines below:

Code: [Select]
                        <?php } else { ?>
                        <a class="category sub-category <?php echo osc_category_slug() ; ?>" href="#"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>

to:

Code: [Select]
                        <?php } else { ?>
                        <a class="category sub-category <?php echo osc_category_slug() ; ?>" href="<?php echo osc_search_category_url() ; ?>"><?php echo osc_category_name() ; ?></a> <span>(<?php echo osc_category_total_items() ; ?>)</span>

Regards

Aficionado

  • Guest
Re: Solution for 404 http header on empty categories/locations
« Reply #9 on: June 09, 2015, 03:52:27 pm »
Thanks, still what do you think it is the best way to handle this ?

404, #, nothing ?


teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Solution for 404 http header on empty categories/locations
« Reply #10 on: June 09, 2015, 04:08:12 pm »
On empty category, vanilla Bender just creates a pseudo-link, Infinity (based on Bender) doesn't put any link at all, Modern gives a normal link => 404 normally, 200 with this modification.

My changes above make Bender acting like Modern, if you're interested in all your categories being indexed by search engines as soon as possible, better always provide a valid link (Modern model).

Regards

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: Solution for 404 http header on empty categories/locations
« Reply #11 on: June 09, 2015, 10:04:36 pm »
long awaited beautiful code :-) thank you!!

lineinfire

  • Newbie
  • *
  • Posts: 8
Re: Solution for 404 http header on empty categories/locations
« Reply #12 on: June 24, 2015, 08:18:46 pm »
This is brilliant. Thanks a ton. :D

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Solution for 404 http header on empty categories/locations
« Reply #13 on: June 24, 2015, 08:43:33 pm »
Okay, this sounds like a good thing but I am a noob when it comes to Google and how they go about 404's let alone any other search engine (do they react all the same?)  ::)

Tell me if I understand correct, the 404 is sent by Osclass in case an ad is no longer available but was indexed by Google?
So this fix tells Google, hey here's your 200 OK page, no 404 problem and Google is happy but you actually let Google keep the lost page indexed? Or is something else happening here?

On empty category, vanilla Bender just creates a pseudo-link, Infinity (based on Bender) doesn't put any link at all, Modern gives a normal link => 404 normally, 200 with this modification.

My changes above make Bender acting like Modern, if you're interested in all your categories being indexed by search engines as soon as possible, better always provide a valid link (Modern model).

Regards

Aficionado

  • Guest
Re: Solution for 404 http header on empty categories/locations
« Reply #14 on: June 24, 2015, 09:56:06 pm »
@Eric

Osclass Modern theme sends a "soft" 404 (404 in http header) for empty categories but SHOWS the page.

The above code is removing that.

Now, for Google, not sure what it is best to do. With any kind of 404 error the categories with no items willl never be indexed. And that for a new website is not good.

Personally i have tried both solutions and i haven't seen any benefit from Google OR any penalty from Google. So i have installed the 404 removal.