Hi I have a website on wordpress which have 2 pages which I meant to convert it to subdomain.

Eg: Let my website at be http://www.domain.com

there are two pages http://www.domain.com/page1 and http://www.domain.com/page2

I want them to be accessible at http://page1.domain.com & http://page2.domain.com respectively.

Also I have may subpages to page1 which i wanna access using subdomain of main page. I mean if http://www.domain.com/page1/subpage1 is subpage of http://www.domain.com/page1 then I want to access it as http://page1.domain.com/subpage1

I have already created subdomains in cpanel pointing them to root folder of my website and tried following htaccess.

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^subsite\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subsite [NC]
RewriteRule ^(.*)$ /subsite/$1 [L]

I have tried different other variants of htaccess code I got from different forums and also www.stackoverflow.com

Also tried WP Subdomains (Revisited) plugin and found of no use.

Please help me to fix it.

1 Answer 1


It's better to use WP_Rewrite for that.

function my_page_rules($rules){
$pageslug = 'sample-page';
$rules['([^/]+)/?$'] = 'index.php?pagename='$pageslug'/$matches[1]';
return $rules;
add_filter( 'page_link', 'sub_page_link');
function sub_page_link(){
// preg_replace here

I have found a premium plugin which uses the same mechanism to convert pages into subdomain, it uses rewrite rules and Server WildCard Configured.

Hope it is helpful!

  • 2
    Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem.
    – kaiser
    Oct 13, 2014 at 12:48
  • @m-ali-salim I think there may be an error in your code example. What does $pageslug resolve to? Feb 26, 2017 at 8:41
  • It is just a code snippet to give an idea, you can get page slug using different methods. i.e $url = getenv( 'HTTP_HOST' ); $domain = explode( ".", $url ); $pageslug = $domain[0]; Feb 27, 2017 at 9:36
  • Avoid the linked plugin in this answer, "WordPress Page Subdomain Pro" - it's not production suitable and has given us lots of problems. The homepage randomly only redirects to a sub domain, sub domains become randomly inaccessible at points. It's also clear to see that the code is very badly written. Do yourself a favour
    – JDandChips
    Mar 29, 2022 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.