Ask your WordPress questions! Pay money and get answers fast! (more info)

URL redirect for custom taxonomy on Posts WordPress

I have created a custom Taxonomy for my Posts called "used-equipment" using the CPT UI plugin.

The settings I have are:

Hierarchical - true
Rewrite Hierarchical - true

The rest of the settings are just the defaults.


My problem is with the URLs for the archive pages.

The standard URL without 'Hierarchical true' for the category "<em>test</em>" which is a child of the parent category "<em>drive-in-rack</em>" is like this:


http://mywebsite.com/used-equipment/test/


When I turn on the settings above (hierarchical true, etc) I get this URL, which is what I want (with the parent category "drive-in-rack" in the URL):


http://mywebsite.com/used-equipment/drive-in-rack/test/


The problem is that the first URL still works but I only want the second URL to work.

So my question is: Can I redirect the first URL to the second one using htaccess? I can do it individually by child category using the redirection plugin, but that's a clunky solution. Or is there a better way to do this?


Answers (2)

2015-08-18

timDesain Nanang answers:

try to re-save "Permalink Settings" once more.

wp will redirect from the first to the second url automatically.



Mike Sewell comments:

I'm afraid it's not that, that's the first thing I did after updating the taxonomy.

2015-08-19

gensmeta answers:

Try adding this to the .htaccess file of the directory you want to redirect <strong>from</strong>, or any of it's parent directories.

RedirectMatch ^/used-equipment/test/$ http://mywebsite.com/drive-in-rack/test/

This should redirect any requests to http://mywebsite.com/used-equipment/test/ to http://mywebsite.com/drive-in-rack/test/

Any text after the "http://mywebsite.com/used-equipment/test/" should automagically be appended to "http://mywebsite.com/drive-in-rack/test/" in the process.


Mike Sewell comments:

Is there any way to make that apply to all child items of the used-equipment taxonomy without having to add a rewrite for each one?


gensmeta comments:

Try this:
RedirectMatch ^/used-equipment/test/(.*)$ http://mywebsite.com/drive-in-rack/test/$1


Mike Sewell comments:

Is there any way to make that apply to all child items of the used-equipment taxonomy without having to add a rewrite for each one?

For example that above would mean I'd need to add a rewrite for each child category of /drive-in-rack/ I can do that with the redirection plugin.

What I'm looking for is if it's possible to create a rewrite rule that will redirect the URL: <strong>sitename.com/taxonomy/child-category/</strong> to the URL which contains: <strong>sitename.com/taxonomy/parent-category/child-category/</strong>

OR if there is a way to stop this URL structure from being created in the first place - sitename.com/taxonomy/child-category