I would do this per server configuration. Here is an example for the .htaccess
:
RewriteCond %{HTTP_HOST} !^blog\.example\.com$
RewriteRule (.*)\.html$ http://blog.example.com/$1.html [L,R=301]
You could do this in a WordPress plugin too. Untested suggestion:
add_action( 'template_redirect', 'wpse_77279_redirect' );
function wpse_77279_redirect()
{
if ( is_single()
and 'blog.example.com' !== $_SERVER['HTTP_HOST']
and 'post' === get_post_type()
)
{
wp_redirect( 'blog.example.com' . $_SERVER['REQUEST_URI'] );
exit;
}
}
Related Posts:
- Display most recent post in category instead of archive?
- Phantom 302 status code when sending a POST requests on pages
- Redirect before post page
- Post preview and oembed provider issue using polylang plugin with subdomains
- Posts are being redirected to xampp home page
- Why is WordPress redirecting users to random posts after commenting?
- Plain permalinks not working!
- Relative redirects for posts, categories, products and product categories
- Multisite: Can’t Post or Create Categories
- 301 (static page instead latest posts)
- Set static page/post from another blog on same network
- Some posts from custom post type to subdomains
- redirect to uploaded (wordpress) post after form submission from front-end
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- How do I Redirect a WordPress Page?
- Subdomain to website directory blog transferring
- WordPress 302 Redirect to Random Product/Post/Page
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- add_rewrite_rule and template redirect not working
- Getting post and attached image from subdomain
- Creating a redirect option for current page url
- How Do I Redirect WordPress Pages but not posts?
- Every time I try accessing a post it redirects me to the feed
- How to Best Create Separate Subscribers and User Experience
- Redirect old Posts URL to new URL
- Redirect to custom post if custom archive page has just one result?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Submit New Post
- Multisite Issue on Subdomain’s article pages
- How to redirect if is post edit or publish page?
- how to redirect page after delete post inside a post page?
- issue in wordpress auto delete post and redirect to another 1
- Relative Image Urls in Posts are starting from root – Not from WordPress Address (URL) at General Settings
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- Redirecting to a post based on a GET parameter and a custom field
- Post pages are redirecting to the 404 page in wordpress
- Is it possible to Schedule Attachments in WordPress?
- Is post ID number always incremental n+
- post__in for get_posts with a dynamic array
- How to hide a post from ‘Recent Posts’ widget?
- Hide add new page button
- Create a separate JS application for an individual post?
- post_parent is 0 when uploading new files
- custom post type grid with content in lightbox [closed]
- Divide Loop Into Days & Categories
- “next_posts_link” and “previous_posts_link” display me NOTHING
- Can I set and show “important” post in my blog?
- Add Post Tags to Body Class
- Understanding and using metaboxes in posts
- How to display different number of posts
- What part of template to edit to remove category name from the top of posts?
- Register post status, exclude from searches
- Ajax Dynamic Archives not showing correct results
- Load post attached images on a single page site with fancybox
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Prevent Delete Attachment by URL or When Submit
- Non-existant URL redirects to existant one
- Post page to display specific category
- Calling Different Custom Post Timestamps in a table
- How do I change the core post search algorithm? Where is it found/constructed?
- wp_posts table: safely remove unused columns to save database storage
- Remove current category from post but display all others
- How to only publish posts with image in it
- Why won’t pagination work?
- How to add some html formated text to every new post in WordPress
- Using system date format
- Posts and Pages: 404 Page not found
- When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
- Post titles and thumbnails as links to custom post types?
- show div only if have a related post inside
- changing parent_id on post
- How do I apply a template to my single posts?
- Help Combine These Two PHP Codes
- How to display list of results
- Problem paginating a subquery on a post
- Reusing old post IDs
- Trigger on DB make problem on wordpress?
- How to show WP admin edit page within template page/post?
- Change post value in WordPress
- Automatic Table of contents with categories and posts
- Rewrite Rule to Combine Taxonomy and Post Type
- Multisite WordPress Configurtion
- Create blog post from external source and set publication date
- Need help with hiding an image within a post in a category
- Delete 100+ posts or media files from wordpress faster than default?
- How to get the postID inside ‘content_save_pre’? Other hook?
- How to filter out post from a category not its subcategory in wordpress dashboard
- How can you control what a user is allowed to post in the backend?
- Hide Certain Tags on Single Post Page
- Deleting first four characters from all Post Titles
- Deleling wordpress posts permanently still have IDs
- wp trim function not working
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Import alt text in set_post_thumbnail
- Moving featured image to top of new post editor screen
- Display posts with id equal to relationship value
- Imported Posts missing summary text on staging site
- Read more opens attachment
- WP_Query post_tilte search in posts table