1

I'm moving my WordPress site to a new host, and in the process I want to make a one time change to the Permalinks. I want to rewrite the URLs from /2015/11/sample-post/ to /sample-post/ but how can I accomplish that?

2 Answers 2

3

The most efficient way to accomplish this would be to change the structure to /%postname%/ and add a 301 redirect to your .htaccess file for the old structure:

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

Change example.com to your domain and add the redirect above the # BEGIN WordPress directive so it won't be removed if WordPress updates the file.

EDIT- redirect /yyyy/mm/dd/postname

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ http://example.com/$4
13
  • Again, We are trying to preserve the old URL of /2015/11/sample-post/ for SEO purposes because those are indexed by search engines, hence I don't want to change the permalink structure in the WP on the referring site. In fact, the WP on referring server will be offline and delete and need to implement this in RewriteRule preserving old URL structure.
    – gmahler5th
    Commented Nov 16, 2015 at 2:11
  • 1
    This will preserve SEO by telling the search bots that the content has been permanently moved to the new structure. This is the method that Google recommends.
    – Milo
    Commented Nov 16, 2015 at 2:13
  • I think I want a way to do this without relying on an instance of WordPress up and running on the referring server. I don't see how changing the permalink in WP will not affect the user experience, it needs a seamless redirect to the new URL structure. Am I missing something?
    – gmahler5th
    Commented Nov 16, 2015 at 2:18
  • The RedirectMatch works to redirect referringserver.com to newserver.com but doesn't redirect URLs as I want them to, such as: referringserver.com/2015/11/post to newserver.com/post
    – gmahler5th
    Commented Nov 16, 2015 at 2:24
  • So your domain name is also changing?
    – Milo
    Commented Nov 16, 2015 at 2:27
0

Go-to settings -> permalink. and than add it like this: %post_name%.

3
  • You misunderstand. On the referring server, I want it to send my new server traffic with hostname.com/sample-post not hostname.com/2015/11/sample-post
    – gmahler5th
    Commented Nov 16, 2015 at 2:04
  • That's what I am also said. Try this before try this one. Take a back up of the existing code and try this. It will solve your problem
    – Kvvaradha
    Commented Nov 16, 2015 at 2:08
  • We are trying to preserve the old URL of /2015/11/sample-post/ for SEO purposes because those are indexed by search engines, hence I don't want to change the permalink structure in the WP on the referring site. In fact, the WP on referring server will be offline and delete and need to implement this in RewriteRule preserving old URL structure.
    – gmahler5th
    Commented Nov 16, 2015 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.