Forum Moderators: phranque

Message Too Old, No Replies

Redirect post to Category using .htaccess

         

mcpilot101

8:40 pm on Sep 10, 2016 (gmt 0)

5+ Year Member



I have a category called publications. I have a slider on the home page that features the latest publications rotating through. When clicked, I would like for any of the linked publications in the slider to go to the main publications page.

the main publications category looks like this:
[url]
www.example.com/publications[/url]

specific URLs for individual publications look like this:

[url]www.example.com/publications/a-very-long-article-name-with-multiple-distinct-examinations-of-blue-widgets-and-red-widgets-and-other-things
[/url]
or

[url]www.example.com/publications/long-hyphenated-article-name-about-disticnt-widget-properties
[/url]
so I would like for any of the individual pubs to redirect back to the category archive because there is never a reason to view an individual publication.

Can someone help?

[edited by: not2easy at 8:52 pm (utc) on Sep 10, 2016]
[edit reason] wigetizing for anonymity [/edit]

whitespace

10:36 pm on Sep 10, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



...because there is never a reason to view an individual publication.


Hhhhmmm, not sure that I understand? Why have "individual publications" (posts?) and link to them, if they can never be viewed?

...what have you tried? Do you have existing directives in .htaccess?

mcpilot101

11:37 pm on Sep 10, 2016 (gmt 0)

5+ Year Member



this particular client publishes scientific journal articles as per of her CV. I set up a custom post type called "publications" with custom fields so that she could simply go in and fill in the blanks (article name, journal name, date published, etc) and it automatically outputs the information in the publications list (similar to a news archive) but there is nothing to look at beyond the basic biolography information.

The issue occurs in that she also wanted a slider on the home page to rotate the most recent publications. That then links the title to the post itself which I dont want. I merely want any link to any of those individual publications to bounce back to the list. It seems like there should be a fairly straighforward "if in publications post type redirect to the acrhive" htaccess process, no?

whitespace

3:12 pm on Sep 11, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Try the following near the top of your .htaccess file in the document root:


RewriteEngine On
RewriteRule ^(publications)/. /$1 [R=301,L]


Any URL of the form "/publications/<something>" will be redirected to "/publications".

(It sounds like you might be using WordPress, in which case this should go above the standard WP routing block. And you only need to include the RewriteEngine directive once, although it doesn't actually matter if it is included more than once.)

not2easy

4:33 pm on Sep 11, 2016 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It seems like there should be a fairly straighforward "if in publications post type redirect to the acrhive" htaccess process, no?

You can redirect easily using a WP plugin if this is a WordPress site. I use Yoast's SEO plugin to manage headers and 301s within WP.

OTOH I don't know that the result is always a good user experience or smiled upon by Google.

mcpilot101

12:58 pm on Sep 12, 2016 (gmt 0)

5+ Year Member



Thank you Whitespace. That works perfectly