Osclass forums
Support forums => Tips, tricks, and tutorials => Topic started 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):
<?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
-
This is one mod that was badly needed. Awesome teseo....as always...Thank You
-
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.
-
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
-
Nice change, thanks TESEO.
Especially on multi-country as subdomains mode this is needed to avoid a HUGE ammount of 404.
-
maybe this is better....
header response 200 ok status header('HTTP/1.1 200 Ok')
and put in meta ="noindex, follow" for empty pages!
!
-
Awesome, been wondering about this empty categories noindexing problem for a while now.. thanks Teseo! ;)
serjuc11111, why noindex,follow?
-
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.
-
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.-
<?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>
2.- A few lines below:
<?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:
<?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
-
Thanks, still what do you think it is the best way to handle this ?
404, #, nothing ?
-
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
-
long awaited beautiful code :-) thank you!!
-
This is brilliant. Thanks a ton. :D
-
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
-
@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.
-
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.
-
@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).
-
Okay, thanks again.
I think I just re-discovered why I had to ask about this.... ;)
-
@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
-
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
-
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)
-
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...
-
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.
-
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>
-
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
-
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 ?
-
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