How to Change Permalink Structure Safely

Currently, I am using domain.com/%year%/%monthnum%/%postname%.html since I migrated from Blogger to WordPress.

But now I want to change to domain.com/sample-post since my posts are evergreen and date & month doesn’t look good in URL.

What’s the safest to do this without affecting backlinks, SEO, etc?

1 Like

@GulshanKumar if I’m not wrong then here we have to use regex redirect. but how you will do this when the value of yousite.com/year/month/postname is changing as per post. Looks like have to add 2-5 regex redirections rules.

1 Like

Add this code in the .htaccess file

# Replace example.com with own domain
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ https://example.com/$4
2 Likes

No need to do anything at Settings>Permalinks?

1 Like

At WP, keep %postname% in advanced before adding above code.

2 Likes

can you explain this rewrite rule @GulshanKumar ?

1 Like

It will redirect from /%year%/%monthnum%/%day%/%postname%/ to /%postname%/ permalink.

I don’t have %day% in URL. Will this code work?

Oh sorry!

Then use this one

From Month and Name /%year%/%monthnum%/%postname%/
To to /%postname%/ permalink.

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(?!page/)(.+)$ https://www.example.com/$3

here this

and here this why?

It depends on how many things I am matching.

Mean I think by rule it’s $1 and your used another number so, I’m confused.