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?
- URL rewriting problem
- openlitespeed rewrite rules conversion from apache
- How can I use an .htaccess file in Nginx?
- 404 Not Found The requested URL was not found on this server
- How to enable mod_rewrite for Apache 2.2
- Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
- Generic htaccess redirect www to non-www
- Apache mod_rewrite Infinite Loop when Accessing WordPress Admin Dashboard
- How do you create a “virtual” page in WordPress
- remove “index.php” from permalinks
- How to create a front end user profile with a friendly permalink
- Use a template file for a specific url without creating a page
- Using the Rewrite API to Construct a RESTful URL
- Does WordPress keep track of a post’s URL history and provide automatic redirects?
- Change the “page” slug in pagination
- Understanding add_rewrite_rule
- Override default url for author pages?
- web.config conflict on IIS
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- Change author base slug for different roles
- Two (or more) parallel (sub-)TLDs that are retained when surfing the site / dynamically set the site address?
- 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 rules not working in WordPress
- How to retrieve $_GET variables from rewritten URLs?
- Dynamic Endpoints
- How to remove dates from existing permalinks?
- Passing parameters to a custom page template using clean urls
- rewrite rules and querystring
- Making a plugin file accessible via url rewrite?
- Adding rewrite endpoint breaks static front page
- How to add custom rewrite rule to .htaccess?
- How do I remove a rewrite rule?
- How do I add a server-independent external rewrite rule?
- Multiple endpoints to same page
- Hosting a WordPress blog as a sub folder from a S3 website
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Custom Permalinks for Blog Posts Only
- Unique URL Every Time
- generate_rewrite_rules (action) vs add_rewrite_rule (function): which one is preferred?
- Detect page type by url (Archive, single, page, author,…)