Osclass forums

Support forums => Tips, tricks, and tutorials => Topic started by: teseo on March 11, 2015, 09:38:58 pm

Title: Solution for 404 http header on empty categories/locations
Post by: teseo 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
Title: Re: Solution for 404 http header on empty categories/locations
Post by: itcafeonline on March 12, 2015, 12:57:02 pm
This is one mod that was badly needed. Awesome teseo....as always...Thank You
Title: Re: Solution for 404 http header on empty categories/locations
Post by: itcafeonline 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.
Title: Re: Solution for 404 http header on empty categories/locations
Post by: teseo on March 19, 2015, 07:28:59 pm
Hi,

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

http://httpstatus.io/ (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
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado 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.
Title: Re: Solution for 404 http header on empty categories/locations
Post by: serjuc11111 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!

!
Title: Re: Solution for 404 http header on empty categories/locations
Post by: p206ab 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?
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado 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.
Title: Re: Solution for 404 http header on empty categories/locations
Post by: teseo 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
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on June 09, 2015, 03:52:27 pm
Thanks, still what do you think it is the best way to handle this ?

404, #, nothing ?

Title: Re: Solution for 404 http header on empty categories/locations
Post by: teseo 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
Title: Re: Solution for 404 http header on empty categories/locations
Post by: design on June 09, 2015, 10:04:36 pm
long awaited beautiful code :-) thank you!!
Title: Re: Solution for 404 http header on empty categories/locations
Post by: lineinfire on June 24, 2015, 08:18:46 pm
This is brilliant. Thanks a ton. :D
Title: Re: Solution for 404 http header on empty categories/locations
Post by: SmaRTeY 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
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado 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.

Title: Re: Solution for 404 http header on empty categories/locations
Post by: SmaRTeY on June 25, 2015, 12:14:10 am
First of all thanks for explaining Aficionado.

So with modern theme (and maybe others) an empty category was 404'ed which Google does not 'like' and the 200 is a fix for this since there's nothing wrong with showing an empty category. I agree 8)

Makes me wonder, should this fix be considered a work-around for a missing feature of Osclass ie. it is Osclass that is generating the 404's or is that not correct?

@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.
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on June 25, 2015, 12:22:45 am
@Eric

Nobody knows what exactly google likes or not, we only guess.

The 404 was used because Google doesn't like "thin" pages, pages with no data. But ads are thin anyway ....

Also a 404 was used because Google doesn't want to display adsense ads to empty pages, still many big sites do with no penalty (Google seems to have rules applied to small sites).

Title: Re: Solution for 404 http header on empty categories/locations
Post by: SmaRTeY on June 25, 2015, 12:41:03 am
Okay, thanks again.

I think I just re-discovered why I had to ask about this.... ;)
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on August 20, 2017, 10:00:29 pm
@Teseo hi, i just did some summer updating and everything for the new "season". Now i see that using OsclassWizards theme, and while i have your function at the end of theme's functions.php, i still see a "#" for empty categories/subcats.

Not sure what changed, i don't even remember what i did or not.

Any ideas ?

Thanks
Title: Re: Solution for 404 http header on empty categories/locations
Post by: teseo on August 20, 2017, 10:12:14 pm
Hi,

Maybe you lose this additional modification:

https://forums.osclass.org/tips-and-tricks/solution-for-404-http-header-on-empty-categorieslocations/msg123531/#msg123531

It's the same for Osclasswizards.

Regards
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on August 20, 2017, 10:18:04 pm
Hi,

Maybe you lose this additional modification:

https://forums.osclass.org/tips-and-tricks/solution-for-404-http-header-on-empty-categorieslocations/msg123531/#msg123531

It's the same for Osclasswizards.

Regards

True. I did the half if it. Missed it.

Many thanks !

 8)
Title: Re: Solution for 404 http header on empty categories/locations
Post by: mrtsoftware on January 25, 2018, 02:14:37 pm
Hi Aficionado, Sory for disturbing...
with above given codes / modification, did you achieve to let to crawl categories, cities, regions which has not item?

What is latest status about 404 increasing errors into Webmaster area and Google's crawling categories, cities, regions which has no item yet...
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on January 25, 2018, 02:59:49 pm
Hi Aficionado, Sory for disturbing...
with above given codes / modification, did you achieve to let to crawl categories, cities, regions which has not item?

What is latest status about 404 increasing errors into Webmaster area and Google's crawling categories, cities, regions which has no item yet...

I have no idea but i see no errors in google webmaster.

But latetly i don't care much, the sites are made for Users and not Google, so as long as i have real human traffic ... it is ok be me.

Title: Re: Solution for 404 http header on empty categories/locations
Post by: mrtsoftware on January 25, 2018, 04:02:13 pm
Above / below given code, should make non item having category url clickable? Right?
I have done on Wizards theme, unable to click : www.antalya-tercume.com

From
<?php } else { ?>
<a class="category <?php echo $_slug; ?>" href="#"><?php echo $_name ; ?></a> <span>(<?php echo $_total_items ; ?>)</span>

to
 <?php } else { ?>
<a class="category <?php echo $_slug; ?>" href="<?php echo $_url; ?>"><?php echo $_name ; ?></a> <span>(<?php echo $_total_items ; ?>)</span>
Title: Re: Solution for 404 http header on empty categories/locations
Post by: teseo on January 25, 2018, 04:18:32 pm
Hi,

There is a second step in that message:

https://forums.osclass.org/tips-and-tricks/solution-for-404-http-header-on-empty-categorieslocations/msg123531/#msg123531

Regards
Title: Re: Solution for 404 http header on empty categories/locations
Post by: Aficionado on January 25, 2018, 04:20:13 pm
Yes, all empty categories/subcatergories should be selectable (not #).

For me the code posted here:

https://forums.osclass.org/tips-and-tricks/solution-for-404-http-header-on-empty-categorieslocations/msg123531/#msg123531

works just (the TWO mods).

Also, checking your site, i see you VIOLATE Google adsense rules, adding Adsense to an EMPTY site. What is the purpose to have adsense in an empty site ?


Title: Re: Solution for 404 http header on empty categories/locations
Post by: mrtsoftware on January 25, 2018, 05:30:59 pm
Yes, site empty and no traffic, I have added it to try how it looks propose, how it looks in mobile devices...etc...

I will remove ads of course... Thank you for warning,


For not # , yes I had forgetten second mod, now Ok. URLS are clickable