vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   404 header on empty threads (https://vborg.vbsupport.ru/showthread.php?t=286662)

agtsai 08-15-2012 11:43 AM

404 header on empty threads
 
When no thread exists, the error page that's says "No Thread specified. If you followed a valid link, please notify the administrator." actually returns a 200 OK header rather than a 404.

Does anyone know how I can modify vbulletin to ensure error pages return a hard 404. Thanks!

Eosian 08-16-2012 01:16 AM

You can do it, but you have add some redundant code to make it happen.

The verify_id() function is what generates that error, so if you want to preempt it you have to throw in a check before it gets called and override what it would've done.

Add a plugin that is triggered by showthread_start

Code:

if (!$check = $vbulletin->db->query_first('SELECT threadid FROM ' . TABLE_PREFIX . 'thread WHERE threadid = ' . $vbulletin->db->escape_string(  $vbulletin->GPC['threadid']) ))
{
// If using fastcgi this is the 404 header
//        header("Status: 404 Not Found");
// otherwise this is the standard 404
        header("HTTP/1.0 404 Not Found");
}

If you don't add an exit after the header you'll throw the 404 instead of the 200, but still show the normal page.

If you want to actually pass the handling to your webserver's error handling document you'd need to either include the error document after it and exit, or similar.

Expert1 03-04-2013 09:43 AM

Thanks alot Eosian, I am looking for this solution for a long. Your solution have worked perfectly for me. But I am getting one more soft error http://www.techhotfix.com/forum/sear...155&pp=&page=3 in search.php. Please help me this type of broken links returning 200 response code or soft 404 instead of 404 error page not found. Please help

Eosian 03-04-2013 11:34 AM

Should be approximately the same but you use search_intro as your hook and the test for whether or not an error has occurred would be to check either empty($errors) or !$show['errors'] (either of those checks, both shouldn't be necessary because the show is set earlier by the $errors variable).

You could probably also use search_complete as the hook, but any other hooks on search_intro could potentially change the results before search_complete is called.

Expert1 03-04-2013 12:20 PM

My brother, actually I have very little knowledge of programming. So please gimme code which have you given in post number 2. Thank You.

Eosian 03-04-2013 12:38 PM

Add a plugin that is triggered by search_intro

Code:

if ( !empty($errors) )
{
// If using fastcgi this is the 404 header
//        header("Status: 404 Not Found");
// otherwise this is the standard 404
        header("HTTP/1.0 404 Not Found");
}


Expert1 03-05-2013 05:24 AM

Hi, above solution is not working brother.
Please check out this link http://www.techhotfix.com/forum/sear...505&pp=&page=2 and i want 404 error but it showing 200 response code. Try to give me some other solution. Thank You.

Expert1 03-06-2013 05:47 AM

Please help me brother.

Expert1 03-13-2013 01:02 PM

Anybody here to help me....

--------------- Added [DATE]1363180009[/DATE] at [TIME]1363180009[/TIME] ---------------

Quote:

Originally Posted by Eosian (Post 2407790)
Add a plugin that is triggered by search_intro

Code:

if ( !empty($errors) )
{
// If using fastcgi this is the 404 header
//        header("Status: 404 Not Found");
// otherwise this is the standard 404
        header("HTTP/1.0 404 Not Found");
}


This is not working....

vbresults 04-11-2013 11:45 PM

Create a plugin hook on the `init_startup` hook, place the following code in, and save.
PHP Code:

if (THIS_SCRIPT == 'showthread' && !verify_id('threadid'$_GET['t'], false)) {
    
header('HTTP/1.0 404 Not Found');
    
header('Status: 404 Not Found');




All times are GMT. The time now is 09:24 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01100 seconds
  • Memory Usage 1,739KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete