4

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.

5

It's better to use WP_Rewrite for that.

add_action('page_rewrite_rules','my_page_rules');
function ($rules){
$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!

|improve this answer|||||
  • 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 '14 at 12:48
  • @m-ali-salim I think there may be an error in your code example. What does $pageslug resolve to? – hitautodestruct Feb 26 '17 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]; – M Ali Salim Feb 27 '17 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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