Skip Navigation

[Resolved] htaccess rewrite rule for custom types

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.48 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by jurgenK-2 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#599500
Screenshot.JPG

I am trying to:
I have a wordpress site with about 7000 pages (custom posts) and the names of these pages will have a small change in the page title/url. You can see the full list here:
hidden link

The URL will change at the beginning of the title. The URL looks now like this:
hidden link
and will change for each item to
hidden link

The logic behind is:
hidden link
will change to
hidden link

To make sure that users will be redirected from the old link to the new link I want to implement a redirect rule in htaccess.

RewriteEngine On
RewriteRule ^friedhof/(.*)/$ hidden link [R=301,NC,L]

But this unfortunately interferes with the rewrite rules of Toolset itself.

I have a funny effect when I put this code in htaccess. the URL will be:
hidden link

The custom post has a custom slug "grabkosten" generated by Toolset -> see screenshot.

When I change the option in Toolset to "Rewrite -> Use the normal WordPress URL logic" the htaccess code works. in the normal WordPress URL logic the slug is called "Friedhof" (hidden link)

Have you got an idea how I can make sure that users will get from
hidden link
to
hidden link

Thanks a lot for your help!

Regards
Jürgen

#599626

Unfortunately I am no expert in -htaccess redirect rules.

I will need to ask a colleague about this on Monday, and I'll update you when I have some additional information.

Thank you for the patience.

#600290

Here's what seems to be working as a redirect for me:

RewriteCond "%{REQUEST_FILENAME}"   "!^grabkosten/grab-auf-"
RewriteRule ^grabkosten/(.*)/$ /grabkosten/grab-auf-$1 [R=301,NC,L]

You have to be sure "grab-auf-" is not already part of the URL, otherwise you'll get the "too many redirects" error. Once you add this redirect, create a new Friedhof post (do not use grab-auf- in the title) and test the permalink. It should redirect to the correct URL with grab-auf-, but it should show a 404 since nothing exists at that URL.

#600412

hm, that works exactly as you describe (great work), but it is not yet the solution I need.

I will manually change all titles to "grab auf-pagetitle", so we have the issue you describe. The redirect should only be for those items which do not have "grab-auf-" in their title.

I copied the site to a test server and manually changed the first item in this list as I want to change all items:
hidden link - First item:
Alter Friedhof
hidden link

This will lead to
hidden link

The point is the following. I want to add "grab" in the URL for SEO reasons. And I do not want to lose the position in Google ranking. So the old URL in search engine listings should redirect to the new URL, but within the site there are the new URL which should not be redirected again.

Is there a solution for this?

Would it make a difference to change the path to /grabkosten/grab-auf/alter-friedhof-rasengrab-wiese-anonym?
This could be another option. I like the other option more as it is more human readable but this could be ok, too.

Thanks a lot, regards,
Jürgen

#600619

Sorry, I'm not sure how to do fix this in either case with htaccess. Toolset's rewrite capabilities are limited to the slug of a CPT, but do not extend to further conditional manipulation. It appears that our best efforts were not much help here. Sorry I wish I could provide you some assistance to accomplish what you're looking for, but it's just not part of what Toolset is designed to do. It might be worthwhile to examine some redirect plugins to try to accomplish this for you.

#601228

Upps, the redirect is automatically...

I talked with my client, and he agreed to make the change without redirecting.

I changed the page title /slug and - voila - the pages are redirected automatically.

Just click here:
hidden link

Thanks for your help anyway.

Have a nice christmas time!

Regards,
Jürgen