简体   繁体   中英

How do I exclude archive directories from a rewrite rule OR rewrite the archive path to include a custom category?

I am struggling with a solution to my problem with a recent wordpress site transition. My old wordpress site had /blog/%category%/%postname%/ as the permalink. With the new site we have changes that to: /news/%category%/%postname%/

I then made a Rewrite Rule to redirect all existing blog posts: RewriteRule ^blog/(.*) /news/executive-insights/$1 [R=301,L]

However, I didn't realize at the time that this also broke all archive URL paths.

Example:

https://www.example.com/blog/2022/04/29/ now redirects to a 404 page of: https://www.example.com/news/executive-insights/2022/04/29/

1.) I either need a fancy way to exclude archive directory(2022,2021,2020, etc.) from the rewrite rule. 2.) Or I need a way to include /executive-insights/ as part of the archive URL path instead of: https://www.example.com/news/2022/04/29/

PS- Please don't tell me to update my custom permalink to include year/month/day that is not a solution.

This solved my problem:

 //=========================================================== // START - Add /executive-insights/ into the archive url path //=========================================================== function change_archive_links() { global $wp_rewrite; // add 'archive' $wp_rewrite->date_structure ='news/executive-insights/%year%/%monthnum%/%day%'; } add_action('init','change_archive_links'); //=========================================================== // END - Add /executive-insights/ into the archive url path //===========================================================

Shout out: How can I change the WordPress archive URL pattern?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM