Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

wordpress - Redirect .htaccess file for old custom post type slug to new slug with post

I have a custom post type with the slug like this: https://mysitename.org/change-wire/post-name-here. Now the CPT has the slug like this: https://mysitename.org/changewire/post-name-here.

Basically, the slug is changed from change-wire to changewire. I would like to automatically redirect any old change-wire. I think a possible solution is to use the RedirectMatch rule but, but I am not sure if this is right:

I can only do it for one post, but I need to it for all posts

This will work for one: Redirect 301 https://mysitename.org/change-wire/post-name-here https://mysitename.org/changewire/post-name-here

How to make this work for all posts with change-wire/{post-name} to change changewire/{post-name} ???

RedirectMatch 301 ???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do it using REGEX:

RedirectMatch  301 /old-slug/(.*) /newslug/$1

In your case

RedirectMatch  301 /change-wire/(.*) /changewire/$1

Here,

(.*) is a wildcard that matches anything that appears after /old-slug/ and saves it to use in the target URL and $1 outputs the first wildcard from source URL expression.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...