简体   繁体   中英

One WordPress Installation Multiple Subdomains wtih same theme and login details

Each subforum will be placed on a different subdomain and use the same Wordpress and template installation. We can using the same accounts/passwords for all subforums/subdomains. Example: hotel.domain.com would display “hotel” sub forum.

user must be able to remain logged-in all subdomains / subforums.

Assuming your web server is configured properly (all subdomains point to the same DocumentRoot), there are two things you need to do to prepare WordPress to handle this kind of installation.

  1. Modify wp-config.php to respond to pre-defined subdomains
  2. Modify your page/post templates to display different content based on the subdomain

Modify wp-config.php

In wp-config.php, you need to add PHP to tell WordPress what the WP_HOME URL is. Because this could be a security vulnerability, you should probably limit subdomains to a pre-defined list. Here is some sample code:

switch ( $_SERVER['HTTP_HOST'] ) {
    case 'subdomain.domain.com':
        define( 'WP_HOME', 'http://subdomain.domain.com/' );
        break;
    case 'subdomain2.domain.com':
        define( 'WP_HOME', 'http://subdomain2.domain.com/' );
        break;
    default:
        define( 'WP_HOME', 'http://domain.com/' );
}

define('WP_SITEURL', WP_HOME);

Add the code above at the top of wp-config.php just before the MySQL settings. DO NOT just do define('WP_HOME', $_SERVER['HTTP_HOST']) as this will allow users to access your site under ANY domain name.

Modify page/post templates

You'll need to add similar host-sniffing code to your page/post templates in order to determine what content to display.

Caveats

When users switch from one subdomain to another, they will need to log in to each. This is probably because the cookie WordPress sends to identify an authenticated user includes the domain (including subdomain). I suspect there is a plugin to help work around this but I am unable to recommend one in particular.

This may not be possible because every WordPress site has its own settings. In these settings are also the permalink settings. meaning that you can only have one domain name. here is a useful link: http://codex.wordpress.org/Using_Permalinks

Um... I may be way off here, but this sounds like a WordPress network, or multi-site...

http://codex.wordpress.org/Create_A_Network

You can even add code to make sure that any user who signs up automatically gets assigned to each site, so they can log in to any one of them, and easily switch between sites while logged in...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM