You can use template_redirect
action hook to achieve that:
add_action('template_redirect', 'redirect_category_posts');
function redirect_category_posts() {
global $post;
if (is_single($post->ID) && in_category('category-name', $post)) {
$new_url = "http://category-name.mydomain.com/{$post->post_name}.html";
wp_redirect($new_url, 301);
exit;
}
}
Please note that both posts in main domain and in sub-domain must have the same slug or post_name
for this code to work.
Related Posts:
- Best Way to Redirect Category to Page and Hide Category
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Preventing index.php?category_name=something from redirecting
- Add forward slash on categories url (serve one version of a url)
- Multisite blog converting categories to subdomains
- Optimal way to redirect home page to category archive?
- How to: 301 Redirect /category/ to /customname/
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- Redirecting category link to first child post
- Redirect category to first available child post
- Redirect category to url with /category
- Changing permalink from /postname/ to category/postname/
- WordPress category page redirects in .htaccess not working
- Why do my categories redirect?
- WP didn’t redirect to canonical category URL
- Sub Categories Keep Redirecting to Pages With Same Slugs
- redirecting from a general category page to another specific one
- Redirect single article permalink to paginated category page
- Automatically redirect a page to a category that share the same slug
- WordPress link to post links to category (loop)
- How to display post in custom file not in archive file?
- Use blog as base for tags and categories
- Category link redirect to custom template page instead of index.php?
- Redirect depending on category chosen
- Need help with major category and permalink re-organization
- Redirect Problems with Archive Page and GET variables
- OK to redirect the root WordPress category slug?
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Category pages redirecting to tab on Posts page grid
- Default URL for category dropdown select option
- WordPress Category url redirects to subdomain
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Paginations in Category Page Leads to Sample Pages
- htaccess redirect for all categories converted to tags now showing 404
- Page redirecting to category (IE only)
- Category Redirection Problem
- How can I hide a category from Contributors in the edit/add new post screen?
- Category page doesn’t use category.php, instead it redirects to homepage
- Multiple post categories – single permalink
- Wrap Post count in a span
- How to exclude uncategorized from permalink structure /%category%/%postname%/
- 404 error on subcategory pages
- Add line breaks in Category description via enter
- Filtering WordPress Contents based on URL
- Display only the latest post from multiple categories
- Mass/Bulk assign categories to posts
- Sticky Posts Not Sticking to Top of Category Archive
- how do I filter single_cat_title to remove all instances of a particlular word
- WordPress order categories by ID
- ACF: Display category name using taxonomy field
- query order by category
- Shortcodes not working in category or tag description
- Post in multiple categories
- Access current post parent and sub category
- Give a page priority over a category that has the same name?
- How to rewrite the post URL according to the category?
- Sticky post for each category on category pages [duplicate]
- ajax for filtering posts by category in wordpress loops
- Question on using custom structures for categories
- How to add orderby parameter for sorting on category.php
- delete category name in the pages
- Tags Instead of Category
- Remove category link
- javascripts files not linking to my category slugs?
- Generating a feed of all but one category of posts
- Pretty URLs with Categories and Tags
- Select posts that match multiple category names, must match all categories listed
- How can i display category title over thumbnail?
- Include home page template in specific category template
- How to use category slug with a regular page
- Display all categories but only if they have posts in them that have a specific tag assigned
- How to fix select filter on category
- Show audio player only in specific post type category
- Check with Jquery if second level checkbox from categories are checked
- display current portfolio categories from a specific parent
- Regarding Tags And Categories
- selecting categories that have products with tag/category
- How to get WooCommerce Product Categories and its children’s children?
- How to hook into creating a category?
- Media Library Category Exclude Tree
- When category name and title are the same … WP will select archive.php instead of single.php
- show posts in archive page based on selected catagory
- How to display child-category PAGES on a category page
- How get all media from a posts category by db?
- Cant get unique_array() work on get_the_category() foreach loop
- Get the categorie name of Event Organiser plugin [closed]
- get_categories returns top-level categories instead of child categories
- Show posts from all categories
- Display the category name of a post that is in two different categories
- how to Specifies an author / editor to edit one category only?
- Show one same template for two category
- My Query is getting the wrong data
- Formating content in category.php
- WordPress Loop Prob
- Display post content from category name using ajax
- WooCommerce category display in custom page
- How to display the category featured images [closed]
- Echo Category In Loop
- hide_empty property not working when using get_terms
- Hierarchical outline of posts