1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

.htaccess non-www to www

Discussion in 'Troubleshooting and Problems' started by yoghurtfarmer, Oct 25, 2010.

  1. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    Noticed my rewrite rule is no longer working and would like some help in fixing it :). Does it have anything to do with the L flag?

    Please and thanks.

    Code:
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data|js|styles|install) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    
    RewriteCond %{HTTP_HOST} ^url\.com$ [NC]
    RewriteRule ^(.*)$ http://www.url.com/$1 [R=301,L]
  2. feldon30

    feldon30 Well-Known Member

  3. yoghurtfarmer

    yoghurtfarmer Well-Known Member

  4. Shadab

    Shadab Well-Known Member

    Any custom rewrite & redirect rules need to be placed before xenforo's rewrite rules.
    Try this:
    Code:
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^url\.com$ [NC]
    RewriteRule ^(.*)$ http://www.url.com/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data|js|styles|install) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
  5. Floris

    Floris Guest

    Death to www. prefix!
    krstep, Miko and CBI Web like this.
  6. yoghurtfarmer

    yoghurtfarmer Well-Known Member

  7. Floris

    Floris Guest

    This is what I use on xenfans to force away the www. part to go back to xenfans.com before anything.

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

    So you could try:

    RewriteCond %{HTTP_HOST} ^xenfans\.com
    RewriteRule (.*) http://www.xenfans.com/$1 [R=301,L]
    Xencored likes this.
  8. wii

    wii Active Member

    that works, thanks

  9. Floris

    Floris Guest

    Glad to hear it did.
  10. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    Figured out it was the trailing dollar sign that was screwing it up, I don't even know why it's there... never noticed because the redirection worked fine in SMF.

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

    I removed the $ and it works fine now :). Thanks for the help everyone.

    So if anyone else is stuck, copy the following and place it immediately after RewriteEngine On and before the Xenforo rewrites.

    RewriteCond %{HTTP_HOST} ^url\.com [NC]
    RewriteRule ^(.*)$ http://www.url.com/$1 [R=301,L]
  11. Brogan

    Brogan XenForo Moderator Staff Member

    What's the fascination/craze with removing www. from URLs now?

    Is it just to be different? For neatness?
  12. feldon30

    feldon30 Well-Known Member

    I think unless you have subdomains, the www is unnecessary.

    The bigger issue is cookie issues when some people visit your website from www. and some don't. So just for cookie reasons, enforcing either www. or no www. is a good idea.
    Dean and Jake Bunce like this.
  13. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    http://no-www.org/

    I favour the www though ;), just looks more balanced to me. Redirects keep everything consistent so you don't end up with two different URLs pointing to the same content. The www and non-www URLs are also indexed separately unless you have redirected them or set a preference in Google Webmaster Tools.

    http://www.www.extra-www.org/
    http://www.yes-www.org/
  14. CBI Web

    CBI Web Well-Known Member

    I haven't even typed 'www' in the address bar for about 5 years now. It's just not necessary anymore. As for having it in the URL, I stopped doing that about 3 years ago. The link that cheeseshredder posted above explains it all.
    1 person likes this.
  15. erich37

    erich37 Well-Known Member

    I do have a rewrite rule so that it always shows "www".
    Because XF-software logged me out when being on the domain including "www" and then entered the domain without "www", so saying I got logged out from the website by just removing the "www" from the URL I typed into my browser....... strange
  16. kuyenmotdivad

    kuyenmotdivad Active Member

  17. Floris

    Floris Guest


    It's like Internet Explorer 6 and vBulletin -> outdated.

    We're in a world now where every 1 year old has an iPad or whatever, and I think by now we can assume people know they're on the Internet and now at gopher or a subdomain.

    Analogue people say: I am on the Facebook
    10 years ago that was: I am on double you double you double you dot come Facebook

    Now they all tweet: I am on Facebook and I google, brb, tweeting, ehl oh elh.
  18. erich37

    erich37 Well-Known Member

    still, try to type facebook.com into your browser, it shows the domain including "www"
    :)
  19. Brother Malachi

    Brother Malachi New Member

    I do this same thing using PHP that i added to the config.php file. It basically does the same thing but doesn't use the mod rewrite engine. Isn't it more...efficient?
  20. feldon30

    feldon30 Well-Known Member

    www. is an optional subdomain.

Share This Page