Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How?
  3. » [SOLVED] 301s

#1 2021-02-04 12:28:39

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,597
Website GitHub Twitter

[SOLVED] 301s

Old sites change, and sometimes, the urls of their pages change too. What happens with the links residing in other sites? Until about a year go, zem_redirect was handling those redirects beautifully, but the very welcome introduction of deep urls, such as section/category/title broke the plugin’s functionality. I have created some 301 rules for some of the urls that attract more visitors, but I would also like to warn those who do land on our site via those outdated urls, that the address of the page they are reading has changed.
Is there a way to detect redirections done via the htaccess and include a notice to update their bookmark(s)?


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#2 2021-02-04 12:49:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,129
Website

Re: [SOLVED] 301s

Bit of a wild guess, but could txp:if_status help? I don’t know if that shows up on the destination page as well. If it works but you don’t know what the original link was, you could still post a “this page’s location has been updated to: <txp:permlink />. Please update your bookmarks accordingly.” notice.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-02-04 13:35:19

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,597
Website GitHub Twitter

Re: [SOLVED] 301s

jakob wrote #328522:

Bit of a wild guess, but could txp:if_status help? I don’t know if that shows up on the destination page as well. If it works but you don’t know what the original link was, you could still post a “this page’s location has been updated to: <txp:permlink />. Please update your bookmarks accordingly.” notice.

if_status does not work in articles, perhaps understandably. I am collecting outdated links from the stats of our site, from many places but admittedly to a limited number of pages (about 120 of them).

I am trying to think how I can implement your suggestion in the error page as
/591/trouble-at-the-interface-2 for example just gets a 404 without the htaccess redirect. The problem exaggerates as the ids of the 404 articles changed so even the code i tried

<txp:permlink id='<txp:page_url type="2" />' />

would return the wrong url. It returns 0, just in case somebody is interested in implementing it.


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#4 2021-02-04 14:43:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,246
Website GitHub

Re: [SOLVED] 301s

How did zem_redirect manage the transfer if the IDs changed? Did you set the rules up by hand? If so, then does smd_redirect not give you the power to handle them?

It’s basically htaccess (wildcard) redirects but at the Txp interface level rather than the Apache level.


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 2021-02-04 15:54:55

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [SOLVED] 301s

If redirects are handled in .htaccess (and everything else fails), you could add some txp-neutral URL parameter to new location links and detect it on landing?

Offline

#6 2021-02-04 17:12:44

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,597
Website GitHub Twitter

Re: [SOLVED] 301s

Bloke wrote #328524:

How did zem_redirect manage the transfer if the IDs changed? Did you set the rules up by hand? If so, then does smd_redirect not give you the power to handle them?

I have no idea how zem_redirect did it. It just worked:) Thanks for the pugin, I’ll experiment with it.

etc wrote #328525:

If redirects are handled in .htaccess (and everything else fails), you could add some txp-neutral URL parameter to new location links and detect it on landing?

That might be a good idea, but as I have the new urls listed for a year or so, and as the new links to the articles are pointing to the correct urls, I would just create another issue.

I could create 120, 301 redirects in htaccess, with some parameters that I can generate in an ‘in-between’ page, but wouldn’t that be too many?


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#7 2021-02-04 17:47:49

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [SOLVED] 301s

I’m not sure to understand your setup. Are “old” links still landing on your site, resulting in 404?

Offline

#8 2021-02-05 06:56:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,597
Website GitHub Twitter

Re: [SOLVED] 301s

etc wrote #328528:

I’m not sure to understand your setup. Are “old” links still landing on your site, resulting in 404?

Short answer
Yes, as many of those links are in pdfs and sites whose owners do not update their bookmarks.

Longer answer

  • We initially had two domains. One for NeMe projects and another one for other peoples’ work.
  • A few years ago, we decided to partly merge them and moved the “texts” section on our main domain. I have done this manually by creating new articles and copying/pasting the body/excerpt but also re-uploading all the images. We also cancelled the second domain, and created a subdomain where we published calls and arts information.
  • The third phase of the migration involved a large number of articles that resided in the subdomain. After consulting this forum, it was rightly suggested that it would be more prudent to export the large db residing in the subdomain, and augment it with what existed in the main domain. The articles from the subdomain now reside in the Blog section, and the articles which were already resided in our main domain, remained there, but with different ids.

The issue is with the “texts” section the articles of which are cited in books, pdfs, and a number of sites.


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#9 2021-02-05 11:47:33

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,129
Website

Re: [SOLVED] 301s

If there’s a pattern to your redirects, e.g. just the domain has changed but not the url-title, then you may be able to drastically shorten your .htaccess rewrites by using regex patterns, e.g. from the subdomain to the blog/ section.

You can’t do anything about the “hard-coded” links in books and pdfs, but Oleg’s idea sounds good:

  • append something like ?redirected=1 to the redirected “stale” links in htaccess.
  • In your page template / form detect if the url parameter is visible. I think <txp:page_url type="redirected" /> should retrieve that, you could then store that as a variable and if_variable whether the value is “1”. Maybe that can also be done in one go with txp:evaluate.
  • If true, show a “please update your links” notice.

That would only show for incoming “stale” links. The correct links would appear as usual…


TXP Builders – finely-crafted code, design and txp

Offline

#10 2021-02-05 11:55:46

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [SOLVED] 301s

jakob wrote #328539:

Maybe that can also be done in one go with txp:evaluate.

<txp:if_request type="get" name="redirected">
    Please update
</txp:if_request>

Offline

#11 2021-02-05 12:05:28

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,129
Website

Re: [SOLVED] 301s

etc wrote #328541:

<txp:if_request type="get" name="redirected">...

Cheers, that was what I couldn’t remember. Much better.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2021-02-05 12:10:47

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: [SOLVED] 301s

jakob wrote #328543:

Cheers, that was what I couldn’t remember.

I had to consult the code myself :-)

Offline

  1. Index
  2. » How?
  3. » [SOLVED] 301s

Board footer

Powered by FluxBB