简体   繁体   中英

Prevent wordpress from changing permalinks after we edit the post

I have a post published in may,2017. The link of the blog will be like ” https://Mysitename.com/2017/05/sample-post/ “. Now I edited the blog in June,2017 and published it. Now the link changed to “ https://Mysitename.com/2017/06/sample-post/ ”. The problem is the old links that I have given is no more working. How can we prevent wordpress from changing the url? Or how can we make the old url work even after edit?

If you want to keep the updated link, you can create a 301 redirect for the old one. This will mean that any users going to the previous link will be directed to the new one.

If you are able to edit the .htaccess file, add the following to line to it with the correct domain and path:

Redirect 301 /2017/05/sample-post/ https://mysitename.com/2017/06/sample-post/

Alternatively, if you do not have access to the .htaccess file, you could install a WordPress plugin that allows you to create 301 redirects.

I hope that helps.

Either way , the permalinks are global, so it may not contain keeping the old values.

You can do that via any redirect URLs Plugin.

This will help you to redirect all the new posts to old dates as well.

I solved the issue.

function _on_wp_post_request( $request ) {
            if ( isset( $request['name'], $request['year'], $request['monthnum']) ) {
                unset( $request['year'], $request['monthnum'] );
            }
            return $request;
        }

            add_action('request','_on_wp_post_request');

This will unset the year and month from the url.

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