Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-06-30 16:26:12

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

410 redirect on previous pages

Hey All,

I have built a site in textpattern that replaces its predecessor that was NOT built in textpattern.

I need to do an 410 redirect on pages that no longer exist but textpattern never had control of them.

My question is how do I get Textpattern to show a proper error page for 410’s using the error_default template.

I have set the 410 redirects in .htaccess file but I dont know how to redirect these to the error_default page.

Any ideas?

Thanks!

Offline

#2 2014-06-30 19:29:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: 410 redirect on previous pages

txpdevcoder wrote #281756:

how do I get Textpattern to show a proper error page for 410’s using the error_default template.

You could just create a Page named error_410 and it’ll get called if the htaccess throws that error. Alternatively if you want to handle it in your error_default page, look at the txp:if_status tag with which you can branch based on status code.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2014-07-01 08:22:34

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: 410 redirect on previous pages

Thanks Stef.

I have these rules in .htaccess

ErrorDocument 410 /default
redirect 410 /gonepage.html

Problem is that when it redirects it seems to be seen as a 404 by textpattern and it loses the 410 status at that point.

Have I done something daft? My error page already has an if 404 / else logic in it that will show a 410 status message if one is triggered but i’m getting the 404 message instead.

Last edited by txpdevcoder (2014-07-01 08:23:14)

Offline

#4 2014-07-01 09:30:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: 410 redirect on previous pages

txpdevcoder wrote #281787:

Problem is that when it redirects it seems to be seen as a 404 by textpattern and it loses the 410 status at that point.

Hmmm, how does one actually trigger a 410 then? 404 being “page not found”, 410 being “gone”, as in the page is not found and is not expected to come back. Not sure how at the network level one would distinguish the two. If your browser visits a page that no longer exists, it’s going to throw a 404 first, right? And it depends on the HTTP protocol in use so you might want to check that.

Is that rule definitely getting processed or is the generic 404 rule being hit? I’m not great at htaccess so maybe someone else will be able to figure this one out, sorry.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2014-07-01 09:39:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: 410 redirect on previous pages

I guess txp is doing the right thing. It searches for the page url, doesn’t find it and throws a 404. There is no way of txp knowing what existed before it was installed.

I would go directly to htaccess (like you did) and set some more specific rules there. Something like

Redirect 410 /old/article.html /gonepage.html
Redirect 410 /old/article2.html /gonepage.html
etc.

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2014-07-01 11:03:42

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: 410 redirect on previous pages

Thanks both for the advice. I have verified the 410 works by disabling the error document rule in .htacces which meant I got a generic Apache server Gone page.

The issue is that the page url stays when it does the redirect. Textpattern tries to serve that page and that triggers a 404.

I aslo have the problem that some of the pages no longer have an equivalent, they are gone completely and cannot be redirected to an actual page. I need an error page to show in this case.

It’s important for SEO reasons that a proper 410 gone is seen by google crawlers etc.

I have a cunning plan that might work. What if i set a section up called error, give at an empty template except for <txp:die/> tag that is set for 410’s with its built in redirect. this should then generate the 410 and serves textpatterns error page with the right messages?

I’ll give it a shot and report back.

Offline

#7 2014-07-01 11:45:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: 410 redirect on previous pages

txpdevcoder wrote #281798:

I have verified the 410 works by disabling the error document rule in .htacces which meant I got a generic Apache server Gone page.

Cool, so HTTP/1.1 then. At least we stand a chance!

So Apache redirects to a Txp page, Txp doesn’t find the resource and triggers a 404 instead of the 410. Which page does it render? The /default section or gonepage.html? I’m a little confused why you need the two rules (cross-ref my ignorance of htaccess). I thought ErrorDocument specifed an action to take if an error of that flavour occurred. Be it a static error message or a redirect.

Also, why the relative forward-slash? Does it work without it? Or with just the redirect? And doesn’t the redirect directive issue a 301 or some other status code? And, for that matter, would the ErrorDocument issue a different status code if it deems it’s redirecting to a non-originating domain? (though in this case, it should see it’s the same domain, so it’s probably not that fouling things up).

set a section up called error, give at an empty template except for <txp:die/> tag that is set for 410’s

If you handoff to any valid Txp endpoint, Txp will probably issue a 200 and <txp:if_status> will just say thanks. If you direct to any invalid endpoint, Txp will trigger a 404. So, yes, the only thing open to you might be a dedicated section designed to “throw” 410 messages for Txp to handle! Seems bizarre, but it’s crazy enough to work.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2014-07-01 12:37:12

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: 410 redirect on previous pages

The gonepage.html was the page that is now gone, not the error for page gone errors.

I tried colaks suggestion but this gave me a 500.

My crazy idea didnt work. If i manually browse to the error page with the <txp:die status="410"/> on it then i get a 410 error page displayed by error_default page.

If i redirect the 410 pages to this page theni just get a blank white screen with just the single word “error” on it.

I think im going to have to resort to a dedicated 410 page. Hopefully google will see it as a proper 410.

Thanks guys for your help.

Last edited by txpdevcoder (2014-07-01 12:37:53)

Offline

#9 2014-07-01 16:25:27

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: 410 redirect on previous pages

txpdevcoder wrote #281805:

I tried colaks suggestion but this gave me a 500.

it might be a case sensitive problem. Did you also try

redirect 410 /old/article.html /410.html

You of course have to create a 410.html page in the root of your domain


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB