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

XF 1.5 Redirecting www to non-www in htaccess

Discussion in 'XenForo Questions and Support' started by Demon_skeith, May 5, 2016.

  1. Demon_skeith

    Demon_skeith Member

    So I have seen a lot of topics on this and used a lot of different codes in attempt to make my domain load without www. but nothing I used in my htaccess file makes it work.

    This is my current set up:

    # Mod_security can interfere with uploading of content such as attachments. If you
    # cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    # SecFilterEngine Off
    # SecFilterScanPOST Off
    #</IfModule>

    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 405 default
    ErrorDocument 406 default
    ErrorDocument 500 default
    ErrorDocument 501 default
    ErrorDocument 503 default

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS_HOST} !^mydomain\.com$
    RewriteRule ^(.*)$ https://mydomain$1 [R=301,L]
    # If you are having problems with the rewrite rules, remove the "#" from the
    # line that begins "RewriteBase" below. You will also have to change the path
    # of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    # This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]



    </IfModule>


    My site does use SSL if that matters for this edit. Far as I know my site uses a basic shared hosting linux server. Any help with this would be appreciated.
     
  2. fernando1027

    fernando1027 Member

    Try

    RewriteEngine On

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} Example\.org$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    on top of all of that delete anything that you add it
     
  3. Demon_skeith

    Demon_skeith Member

    So I have it like this:

    RewriteEngine On
    RewriteCond %{HTTPS_HOST} !^mydomain\.com$
    RewriteRule ^(.*)$ https://mydomain$1 [R=301,L]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} mydomain\.com$
    RewriteRule ^ https://mydomain%{HTTP_HOST}%{REQUEST_URI}[L,R=301] (not sure if I put my domain in this line, tried it both ways with same result)

    and didn't work.
     
  4. fernando1027

    fernando1027 Member

    try my and edit where it says Example\.org < you put your domain there only
     
  5. Demon_skeith

    Demon_skeith Member

    hrmmm, still not working. Maybe I'm putting my domain in wrong?

    full thing:

    RewriteEngine On
    RewriteCond %{HTTPS_HOST} !^gaminglatest\.com$
    RewriteRule ^(.*)$ https://gaminglatest.com$1 [R=301,L]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} gaminglatest\.com$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
     
  6. fernando1027

    fernando1027 Member

    delete
    what you have there and just add

    RewriteEngine On

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} gaminglatest\.com$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    above your file

    it should look like
    ( make sure you file it is call indeed .htaccess and not htaccess.txt)
    .............................................

    RewriteEngine On

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} gaminglatest\.com$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



    # Mod_security can interfere with uploading of content such as attachments. If you
    # cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    # SecFilterEngine Off
    # SecFilterScanPOST Off
    #</IfModule>

    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 405 default
    ErrorDocument 406 default
    ErrorDocument 500 default
    ErrorDocument 501 default
    ErrorDocument 503 default

    <IfModule mod_rewrite.c>
    RewriteEngine On

    # If you are having problems with the rewrite rules, remove the "#" from the
    # line that begins "RewriteBase" below. You will also have to change the path
    # of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    # This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
     
    Last edited: May 5, 2016

Share This Page