Rewrite individual article URL to the section page
In the new IMCA site I had a section with one article which I wanted to appear in search but I also did not want it to appear in its normal url but on the landing page of the section.
The problem is with the search results where the articles appear with their urls. What I had to do is to rewrite their individual urls to the section ones.
A big thanks goes to Robert (wet) who came up with a solution for my problem (the code below).
The code I use
<txp:if_article_section name="about"> <txp:php> txp_status_header('301 Moved Permanently'); header('Location: http://mysite.tld/about/'); exit; </txp:php> </txp:if_article_section>
How it works
if_article_section tag is very handy when checking if the article in question matches a named section. From Textpattern Docs:
The tag will execute the contained statements if the section name associated with a particular article matches the value of the name attribute.
So, if the user visits the article URL then he or she will be redirected to the section page and the URL will be rewritten.
Check out the result
To see this in action, visit this link – check the url of the article returned in the search results and then click on it and look at the page url.
If you use this code, don’t forget to edit
header('Location: http://mysite.tld/about/'); to match your chosen URL.