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

Redirecting www to non-www

Discussion in 'XenForo Questions and Support' started by Carl, Apr 2, 2011.

  1. Carl

    Carl Well-Known Member

    Can someone please clarify how to specify the file to remove the www. i havent been able to get it to work the other way around. Thanks :)
  2. Brett Peters

    Brett Peters Well-Known Member

    This is what I used

        # Redirect if www.example.com (case-insensitive) to example.com
        RewriteCond %{HTTP_HOST} ^www.yoursite\.com [NC]
        RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
    Carl likes this.
  3. yavuz

    yavuz Well-Known Member

    Neither of these worked for me. My .htaccess looks like this:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule f[\d]+/.+-([\d]+)/index([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
        RewriteRule f[\d]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]
        RewriteRule f([\d]+)/index([\d]+).html forumdisplay.php?f=$1&page=$2 [NC,L]
        RewriteRule f([\d]+)/ forumdisplay.php?f=$1 [NC,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]
  4. Carl

    Carl Well-Known Member

    Is this correct if the forum is in the forum subdirectory?

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.mileskane\.org/forum$ [NC]
    RewriteRule ^(.*)$ http://mileskane.org/forum/$1 [R=301,L]
  5. Brogan

    Brogan XenForo Moderator Staff Member

    There's no need to specify the installation directory.
    This is what I have in my root .htaccess, despite my forum being in the /community directory.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} www.example.com$
    RewriteRule ^(.*)$ http://example.com$1 [R=301,L]
  6. Carl

    Carl Well-Known Member

    It wont work for me then - it redirects to my forum homepage (im wondering if the htaccess in my wordpress installation is affecting it.) :mad:
  7. Brogan

    Brogan XenForo Moderator Staff Member

    Is WordPress in the root?

    Do you have any other rewrites in your root .htaccess?
  8. Lucas

    Lucas Well-Known Member

    This works for the root directory, but not if I access the forum as http://www.example.com/community, it'll still keep the www.
  9. Brogan

    Brogan XenForo Moderator Staff Member

    It works on my installation.
    All servers seem to be set up slightly differently as I tried several different versions, which all work elsewhere, before finding one that worked for me.
  10. Kier

    Kier XenForo Developer Staff Member

    This is ours:
    RewriteCond %{HTTP_HOST} !^xenforo\.com$
    RewriteRule ^(.*)$ http://xenforo.com$1 [R=301,L]
  11. Carl

    Carl Well-Known Member

    Just gave that one a try Kier and it redirects to my wordpress homepage. :)

    Yes the wordpress installation is in the root

    These are the contents of that .htaccess
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
  12. Carl

    Carl Well-Known Member

  13. Brogan

    Brogan XenForo Moderator Staff Member

    Try removing the wordpress rewrites temporarily just to test which version of the non-www works.

    Once you've determined which one works, you can then work on trying to integrate them.
  14. Carl

    Carl Well-Known Member

    It's ok I've given up. Thanks.

Share This Page