PDA

View Full Version : 404 header on empty threads


agtsai
08-15-2012, 11:43 AM
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


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/search.php?searchid=430155&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


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/search.php?searchid=431505&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 1363180009 at 1363180009 ---------------

Add a plugin that is triggered by search_intro


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.
if (THIS_SCRIPT == 'showthread' && !verify_id('threadid', $_GET['t'], false)) {
header('HTTP/1.0 404 Not Found');
header('Status: 404 Not Found');
}

motorhaven
04-18-2013, 09:24 AM
If you put the above in init_startup it messes up tab ids and tab text. You'll get something like this in your tabs:

#vbtab_forum# #vbflink_bbmenu# #vbflink_newposts# #link_mzew_621# #vbflink_pms# #vbflink_faq
etc.

tpearl5
09-30-2013, 04:43 PM
has anyone found a better way to do this?

M.C.
10-01-2013, 09:09 AM
there is a hack for error pages: https://vborg.vbsupport.ru/showthread.php?t=281410

tpearl5
10-01-2013, 12:49 PM
there is a hack for error pages: https://vborg.vbsupport.ru/showthread.php?t=281410

That's similar, but not the same thing as discussed above. The problem is that deleted threads don't return a 404.

M.C.
10-02-2013, 05:17 AM
Ahh.. Ok, sorry...

May be is better to edit template and add redirector?

So I use same hack I mention.

Now edit template:
STANDARD_ERROR

find:
{vb:raw headinclude}

replace:
<vb:if condition="$show['permission_error'] OR $show['inlinemod_form']">{vb:raw headinclude}<vb:else />
<!-- redirect -->
<script type="text/javascript">
<!--
location.replace("http://path_to_your_error_page/forum/404.php"); -->
</script>
<noscript>
<meta http-equiv="refresh" content="0; url=http://path_to_your_error_page/forum/404.php">
</noscript>
<!-- redirect -->
</vb:if>

synseal
04-23-2014, 03:52 PM
Hi did anyone figure out how to fix this issue, I see many threads about it but no working solutions? tia.

vbresults
04-23-2014, 04:34 PM
If you put the above in init_startup it messes up tab ids and tab text. You'll get something like this in your tabs:

#vbtab_forum# #vbflink_bbmenu# #vbflink_newposts# #link_mzew_621# #vbflink_pms# #vbflink_faq
etc.

I came up with a fix to this, PM for more details.