1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need help with my .htaccess file.

Discussion in 'Apache' started by CarpCharacin, Aug 14, 2016.

  1. #1
    I am trying to redirect all non www urls to www urls. I am using xenforo. This is what I put in my .htaccess file and it isn't working
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Code (ApacheConf):

     
    Solved! View solution.
    CarpCharacin, Aug 14, 2016 IP
  2. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #2
    #Force www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

    Try adding the url. At a glance it seems to me your code should probably work though.
    N.
     
    Nigel Lew, Aug 14, 2016 IP
  3. CarpCharacin

    CarpCharacin Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #3
    I did it and it didn't work.
     
    CarpCharacin, Aug 14, 2016 IP
  4. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #4
    Nigel Lew, Aug 14, 2016 IP
  5. CarpCharacin

    CarpCharacin Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #5
    it is www.utahfishkeepers.us. I have freindly URLs on.
     
    CarpCharacin, Aug 14, 2016 IP
  6. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #6
    Ahh it could very well be the case that htacces is not enabled in Nginx. You are not serving stuff with apache.

    HTTP/1.1 200 OK => Server => nginx

    You would need to be able to take a look at nginx.conf I don't think you can just drop one in the root folder like .htaccess. You will probably have to ping your host on this one if you don't have root access.

    Here is a pretty handy tool to convert that rule if need be. http://winginx.com/en/htaccess

    hope that helps a bit,
    Nigel
     
    Nigel Lew, Aug 14, 2016 IP
  7. CarpCharacin

    CarpCharacin Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #7
    The web host said I had to enable it in .htaccess and i did that. The .htaccess file came with xenforo and i renamed it from .txt and it works with freindly URLs. The freindly URLs didn't work before I renamed the .htaccess. The host says to use .htaccess.
     
    CarpCharacin, Aug 14, 2016 IP
  8. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #8
    Strange stuff. Can you paste the htaccess file? Its probably something simple.

    N.
     
    Nigel Lew, Aug 14, 2016 IP
  9. CarpCharacin

    CarpCharacin Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Here it is:
    #    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>
    #Force www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^utahfishkeepers.us [NC]
    RewriteRule ^(.*)$ http://www.utahfishkeepers.us/$1 [L,R=301,NC]
    Code (ApacheConf):
     
    CarpCharacin, Aug 14, 2016 IP
  10. #10
    Try sticking this on line 19 instead
    RewriteCond %{HTTP_HOST} ^utahfishkeepers.us [NC]
    RewriteRule ^(.*)$ http://www.utahfishkeepers.us/$1 [L,R=301,NC]

    and delete it from the bottom.


    you are invoking rewrite engine on twice. Not sure what the implications of that are but you likely want that rule higher before it starts trying to parse other stuff as well.

    Also change this
    #RewriteBase /xenforo

    to this RewriteBase / if it doesn't work.
     
    Nigel Lew, Aug 14, 2016 IP
  11. CarpCharacin

    CarpCharacin Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #11
    It worked the first time! Thank you very much for your help!
     
    CarpCharacin, Aug 14, 2016 IP
  12. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #12
    Sure thing. Glad I could help.
    N.
     
    Nigel Lew, Aug 14, 2016 IP