0

I have a wordpress site that is accepting domain.com, but not www.domain.com.

my httpd.conf looks like:

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot "/var/www/html/domain"
</VirtualHost>

my .htaccess looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

and my wp-config.php has the below:

define('WP_HOME','http://domain.com');
define('WP_SITEURL','http://domain.com');

yes. I changed the domain name. How do I get it to accept www.domain.com in addition to domain.com. If a user goes to www.domain.com, every page loses their logged in status and logs them out.

Thanks.

arcee123
  • 539
  • 3
  • 32
  • 86
  • 3
    Why don't you change to redirect approach? Enabling 2 server aliases will diverge your website statistics (SEO). If you decide to follow the redirect approach, see this link: http://stackoverflow.com/a/4916313/5240430 – André Bonna Aug 12 '16 at 02:39
  • That worked. Thanks. – arcee123 Aug 12 '16 at 13:11

1 Answers1

1

One way you could get it to allow both or any domains would be to do this in your wp-config.php file:

// Allows logins to persist across any subdomain:
define( 'COOKIE_DOMAIN', '.domain.com' );

// Sets home URL dynamically based on how site is accessed:
if ($_SERVER['HTTP_HOST'] == 'domain.com') {
    define('WP_HOME','http://domain.com');
    define('WP_SITEURL','http://domain.com');
} 

if ($_SERVER['HTTP_HOST'] == 'www.domain.com') {
    define('WP_HOME','http://www.domain.com');
    define('WP_SITEURL','http://www.domain.com');
}

Here's more info on setting the cookie domain name option.

Ben Cole
  • 1,537
  • 1
  • 11
  • 18
  • May be it is not the best solution, but it could be a "patcth" for some specific cases... – terox Aug 21 '19 at 14:04