change home_url and site_url but don’t redirect to home_url and site_url on load

You need to set the WP_SITEURL and WP_HOME in wp-config.php file. Please add below code. define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); In your server SSL setup then used below code define(‘WP_SITEURL’, ‘https://’ . $_SERVER[‘HTTP_HOST’]); define(‘WP_HOME’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);

How to redirect?

You can do something like this, add_action(‘wp’,’special_redirect’); function special_redirect(){ global $post; if( $post->ID == 123 ) // put your post id { if ( ! wp_get_referer() ) // false if you access directly { wp_safe_redirect( get_home_url() ); // if so redirect to home } } } It should work. I’ve tested it.

Redirect after Permalink change – What regex do I use?

You can do this by regex rewriting the legacy URL as a query. You can do that either on the post_id or the postname, in this case I think the postname is probably safer (avoids false matches on some other path that might start with numbers). In custom functions, something like this: add_rewrite_rule( ‘^[0-9]+/(.*)/?’, ‘index.php?&name=$matches[1]’,’top’ … Read more