To redirect example.com/pagecategory/page-single to pagecategory.example.com/page-single, where pagecategory is entirely variable then you can do something like the following at the top of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^([a-z]+)/([\w-]+) https://$1.%{HTTP_HOST}/$2 [R,L]
I’ve limited the “subdomain” (ie. pagecategory) to just the lowercase characters a-z – this is saved in the $1 backreference. Likewise, $2 holds the “page-single”.
Note that this is a 302 (temporary) redirect. Change R to R=301 if this is intended to be permanent, but only once you have confirmed it works as required (to avoid browser caching issues).
Related Posts:
- Sub domain redirection to taxonomy
- Change pagination url format
- Can’t get pretty permalinks to work without index.php
- htaccess – Redirect to subfolder without changing browser URL
- How to create custom URL routes?
- Masking wp-content/themes/name/images to just images directory using htaccess
- Use subdomain for certain urls
- How to change default page slug?
- Using WordPress with Apache behind an nginx reverse proxy
- Mod_rewrite delete parameter in 301 Redirect
- Need to make a php file inside theme accessible via url
- Rewrite URL to remap WordPress Permalink
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- How to add a custom redirect rule for subdomains?
- Using custom mod_rewrite without breaking wordpress permalinks
- Rewrite rule to load images from production does nothing
- Rewrite Rules Are Redirecting and Not Passing VARs
- WordPress rewrite rules don’t need ^?
- How to redirect http://mydomain/blog/blahblah/ to http://mydomain/blahblah/ in wordpress htaccess?
- Adding rewrite rules directly to .htaccess file
- Custom rewrite not working
- WP is ignoring .htaccess rewritten URL
- a one-off rewrite rule
- How to configure Multisite Network with randomized hostnames?
- Rewrite wp-login.php URLS to static pages?
- Need help with simple rewrite rule (shouldn’t this be easy?)
- Change htaccess to redirect to index.php in subfolder
- Rewrite custom post type URL parameters
- How to remove wordpress directory slash
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- URL Rewriting for PHP script on an image URL
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- How to rewrite wordpress urls with index.php in them
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Map secondary domain to other’s virtual subfolder
- Rewriting a subdomain page on one WordPress installation to a parent domain on another
- URL rewriting with custom user meta “/%shop_name%/gallery/%gallery%”
- Changing URL scheme, mod_rewrite not helping
- How to redirect a link to a new link?
- Localize URL bases
- How can I create custom URL routes?
- force www rewrite if wordpress put in a folder
- Rewriting a date hierarchy into a ‘yyyy-mm-dd’ slug
- How do I make WordPress revise an .htaccess file a certain way?
- modify URL with mod_rewrite or hook
- How to change an existing wordpress page rewrite rule?
- Pretty URL via Rewrite
- URL Rewrite 404
- ModRewrite not working properly
- How to create short urls for sharing and downloadable content?
- Custom Rewrite for Profiles
- Function to rewrite URl in WordPress
- help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]
- How to redirect a virtual page (e.g. /blog) to the home page?
- Generated URLs don’t reflect accurate URLs.
- Please give me the rewrite rules for my ugly urls
- Add rewrite endpoint and .htaccess
- WP-Include rewrite directory
- Is it possible to use the same slug structure for a taxonomy and for some pages?
- openlitespeed rewrite rules conversion from apache
- How to create a front end user profile with a friendly permalink
- Using custom/dynamic “slug” for a page
- How to make pages slug have priority over any other taxonomies like custom-post, post or category
- Rewrite URL – how to do a SEO-friendly Unicode custom URL?
- How do i change the search permanent links
- add_rewrite_rule() not playing nice with child pages
- Custom comments
- How to Change Author Posts URL
- Change permalink for default archive – yearly
- How to perform a query at the URL?
- Is there a way to create alias without using htacess, permalinks or delving into code?
- add_rewrite_rule fro html to another url not working
- How to rewrite url wordpress?
- I want to add a new tag to WordPress URL permastruct
- Unable to get /%postname%/ permalinks working, 404 on all links
- htaccess rewrite ignored
- Best way to trigger rewrite rules
- Trouble with question mark in rewrite rule
- What to do when WordPress posts on a new server return an error 404
- Redirect htaccess [closed]
- Weird characters behind every single link and images
- How to mask url of a specific page without affecting seo [closed]
- Mobile version and URL Rewrite
- Adding Theme File for Non-WordPress Content
- Show index.php template instead of 404 page template
- WordPress dynamic page handle in theme
- Rewrite htacess rule doesn’t work
- I have a problem with WP_Rewrite
- How to create dynamic URLs on WordPress?
- ../../page-name backend links are not rewritten
- 404 Rest Route not found – when serving behind “proxy”
- Prefix only some posts with a custom prefix
- rename author base from author url in wordpress not working
- Rewriting / Redirecting request outside wordpress
- Finding and removing unnecessary redirects
- Needed to change slug to access page
- mysite.co.uk/wordpress redirects to mysite.co.uk?
- List posts with same tag?
- Changes done to .htaccess are not getting reverted back
- Help with url rewrite