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

The default .htaccess file

Discussion in 'XenForo Questions and Support' started by AndyB, Apr 4, 2013.

  1. AndyB

    AndyB Well-Known Member

    On my forum I use the "Use Full Friendly URLs" and don't use the "Include Content Title in URLs".

    pic001.jpg

    An example of my URL looks like this:

    http://www.mysite.com/forums/threads/12345/

    I would like to know if I need a .htaccess file at all. Here's the default .htaccess file I'm currently using:

    Code:
    #    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 500 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>
    
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes you need the .htaccess file. The rewrite rules enable removal of "index.php" from the URL.
     
  3. AndyB

    AndyB Well-Known Member

    Hi Jake,

    Thank you answering my question.

    What does this portion of the .htaccess file do and is it needed?

    Code:
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Jake Bunce likes this.
  5. AndyB

    AndyB Well-Known Member

    Thank you, Chris, that link is extremely helpful.

    As Jake indicated, this part of the .htaccess file is needed to remove the "index.php" part of the URL.

    Code:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        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>
    
    Could someone explain what these lines do. Are they all needed? Could the same be done with fewer lines?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If the server has mod_rewrite then turn on mod_rewrite. If the requested resource exists on the server then let it pass and do nothing. If it doesn't exist and it's not a known XF directory or file then send the request to index.php to be used as a friendly URL.

    Yes. No.
     
  7. AndyB

    AndyB Well-Known Member

    Thank you, Jake.
     

Share This Page