0
votes

So I have a wordpress site that I'd like to 301 redirect to a different domain, BUT the original domain permalink has the date in the URL, /yyyy/mm/dd/postname

domain.com/%year%/%monthnum%/%day%/%postname%/

And I just want it to have the /%postname%/ like

domain2.com/%postname%/

I tried changing the permalink and using the Redirection plugin to setup a regex, but that didn't work. Is there another way?

1

1 Answers

1
votes

You can also Redirect through code by using Wordpress Function, Please Add Post_id of 'domain.com/%year%/%monthnum%/%day%/%postname%/' and in URL you can add redirect URL wherever you want to redirect

function my_logged_in_redirect() {
    $post_id = url_to_postid( 'domain.com/%year%/%monthnum%/%day%/%postname%/' ); 
    if ( is_user_logged_in() && is_page( $post_id ) ) 
    {
        wp_redirect( 'domain2.com/%postname%/' );
        die;
    }

}
add_action( 'template_redirect', 'my_logged_in_redirect' );

I hope this will helps you!