Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Solving WP-410 incompatibility with WP Super Cache WordPress

  • SOLVED

I have [[LINK href="http://wordpress.org/extend/plugins/wp-410/"]]WP-410[[/LINK]] plugin installed to send HTTP 410 gone responses to posts that I have deleted which is around 1000 of them.

I also have WP Super Cache installed which after testing seems to work better than other caching plugins.

I just found that that having this two plugin installed creates a disaster and I'm looking for a solution to this problem.

If I clear the cache, accessing the deleted post will correctly serve a 410 Gone status code because of the WP-410 plugin. However after the first visit, a cached page will be created by WP Super Cache for the deleted post and will then serve a 200 OK code!

Probable solution:

1. At the Advanced tab of WP Super Cache, there is a textbox to specify the string of URL not to cache and it works fine after testing. However this is not a good solution since I have over a thousand URLs.

2. Manually hack/edit either WP Super Cache or WP-410 so that they work side-by-side.

3. I can create an empty folder using the same slug name of the deleted post:

Example URL of deleted post: http://www.abc.com/this-is-deleted-post-slug/
Create an empty folder this-is-deleted-post-slug at the root of www.abc.com

Put in an index.php with a header code to send 410:

<?php
header('HTTP/1.1 410 Gone');
?>


And finally load (not redirect) the activated theme's 404.php file to show the customized not found page to visitor. This is the part that I have no idea how to do it.

<strong>Final Note</strong>: I prefer the third method because I can avoid using WP-410 plugin. If you can guide me to it, suggest me your prize and it'll be awarded to you.

Answers (4)

2013-04-14

Dbranes answers:

You could try to turn off caching for the 410 pages by adding this to your functions.php file in the current theme directory:

add_action('wp_410_response','no_cache');
function no_cache() {
$GLOBALS['cache_enabled']=0;
$GLOBALS['super_cache_enabled']=0;
}


with both the plugins wp-410 and wp-super-cache installed.


Dbranes comments:

This seems to be working on my Wordpress install with both plugins installed.

With the above code snippet I get these responses on page reloads:


HTTP/1.1 410 Gone (1st reload)
HTTP/1.1 410 Gone (2nd reload)
HTTP/1.1 410 Gone (3rd reload)
...


Without it, I get these response


HTTP/1.1 410 Gone (1st reload)
HTTP/1.1 200 OK (2nd reload)
HTTP/1.1 200 OK (3rd reload)
...


raymond comments:

That works. I've voted for you.

2013-04-14

Hai Bui answers:

You can modify the WP 410 plugin to prevent WP Super Cache from caching deleted posts. Insert this line after line 339 in wp-410.php:
define('DONOTCACHEPAGE', true);


raymond comments:

Works as well, voted.

2013-04-14

Gabriel Reguly answers:

Hi Raymond,

For 3rd solution, I wonder if


<?php
header('HTTP/1.1 410 Gone');
http_response_code(410);
header('location:http://yoursite.com/404');
?>


would not work?

Regards,
Gabriel

-Edit - added http_response_code(410);


raymond comments:

Sorry, I don't want to redirect them to another page but I want to load the 404.php content from my theme.

Just like when you visit an invalid page on Wordpress, you're not redirected but will be shown what's in the 404.php.


Gabriel Reguly comments:

Hi Raymond,

But that is exactly what I wanted to do, or do you have a 404 url at your site?

If so use another invalid URL for your site.

It would trigger the 404 template from WordPress in the easiest way.

Regards,
Gabriel


Gabriel Reguly comments:

Hi Ramoynd,

Another solution would be bootstrap WordPress and load 404 template manually, but why all the trouble if a redirect would be easier to do?

Please let me know if you want that solution.

Regards,
Gabriel

2013-04-14

Daniel Yoen answers:

To prevent cache for certain page, you can define the constant DONOTCACHEPAGE on the front page.

or you can try this :

header('HTTP/1.1 410 Gone');
header("Location: ".get_bloginfo('url'));
exit();


hope this help :-)


raymond comments:

I can't define DONOTCACHEPAGE because that post is not even available.
What does the line below do?
header("Location: ".get_bloginfo('url'));


Daniel Yoen comments:

redirect to homepage

if you don't want to redirect, try this :

if (strstr($_SERVER['REQUEST_URI'],'index.php')){
header('HTTP/1.1 410 Gone');
include /404.php //your correct location 404.php page
exit();
}


Daniel Yoen comments:

if (strstr($_SERVER['REQUEST_URI'],'index.php')) //if page not found
{
header('HTTP/1.1 410 Gone');
include /404.php //your correct location 404.php page
exit();
}


raymond comments:

Where do I put the code in?
Into index.php at the slug folder that I create?


Daniel Yoen comments:

wait, could you give me the link, please :-)


Daniel Yoen comments:

i think, you just need to add :

header('HTTP/1.1 410 Gone');

before get_header in 404.php file in theme folder

<?php

header('HTTP/1.1 410 Gone');

get_header(); ?>


you will get this :