4

My drupal site is apparently accessible as both 'www.domain.com' and just 'domain.com'. Does anyone know of a way to remove the 'www' accessibility, or at least redirect users who go there to the 'domain.com' domain?

I've installed Global Redirect module but am not seeing options that solve this problem. Does Global Redirect module solve this problem or is this a stackoverflow question?

8

If you're using Apache with your setup, this is built into the .htaccess file that comes with the distribution of Drupal. Look for the following code and follow the instructions in the comments:

  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

You'll have to replace example.com with your own site's domain.

  • follow up question. That works on some of my sites. But on one of them my site stops working entirely if I make that change (I've made sure that the other one - use 'www' is still commented out). My site information also says www.mysite.com. i tried changing the base_url var in settings.php to domain.com but that didn't help. Any thoughts on why this might be happening? (a server issue maybe...) – Sage May 19 '15 at 6:27
  • What are the symptoms? White screen? HTTP 500 error? Depending on the problem there are different ways to troubleshoot. – Shawn Conn May 19 '15 at 18:03
  • that makes sense. So as soon as I uncomment the two lines beneath 'to redirect all users to access the site WITHOUT the 'www' prefix', I then go to my site (at either www or without it) and get this: "Problem loading page" (title) The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies. – Sage May 19 '15 at 19:15
  • That sounds like a redirect loop; there are probably other .htaccess (or other Apache conf) redirect rules chained together that's causing it bounce back between two URLs. The FF network inspector should show the looping requests. – Shawn Conn May 19 '15 at 19:19
  • ok, did that. the requests are all 301 and flip back and forth between domain.com and www.domain.com (all of them GET requests until the final one which says POST). The file for each request is '/' until the final one which says 'event'. – Sage May 19 '15 at 19:44

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.