I want my visitors to see http://www.example.com rather than the same url without the "www". I have multiple domians pointing to the same Drupal instance, and use the Domain Access module to restrict access appropriately.

However, I cannot seem to get the access rules to work on the domains with and without the "www".

For example:

Say there is a page set to display only on the www.example.com domain at http://www.example.com/page. If one types in http://www.otherdomain.com/page, they are properly blocked from access as expected. However if one enters http://otherdomain.com/page, they get the content that should only be showing on the www.example.com domain.

It would seem that if I want all pages displayed without the "www" option, Domain Access provides a feature to handle the url rewrites. How does one enforce content access when they DO want the "www" portion displayed?

I've tried listing the domains both with and without the "www" in the domain record of the module, but nothing seems to work.

Could anyone assist? I know I could do redirects via .htaccess, but I have several domains and would rather not deal with changing the .htaccess every time I add or remove one.

Comments

agentrickard’s picture

You might have to use Domain Alias to force a redirect from 'example.com' to 'www.example.com'. That might be easier than a rewrite rule in .htaccess. However, a proper regex in .htaccess could always append www.* to your domains.

TwistedLincoln’s picture

Thanks very much for the suggestion! I couldn't get Domain Alias to redirect from 'example.com' to 'www.example.com' for some reason, however adding the following to my .htaccess file did the trick for all of my domains:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

TwistedLincoln’s picture

Thanks very much for the suggestion! I couldn't get Domain Alias to redirect from 'example.com' to 'www.example.com' for some reason, however adding the following to my .htaccess file did the trick for all of my domains:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

agentrickard’s picture

Status: Active » Closed (fixed)