Some Default .htaccess Configurations

.htaccess files override default server settings and set rules and parameters for the directory they are in, as well as directories inside that directory. Here are some common default .htaccess file configurations for some scripts that you might find helpful.



WHMCS

RewriteEngine On
     
    # Announcements
    RewriteRule ^announcements/([0-9]+)/[a-z0-9_-]+\.html$ ./announcements.php?id=$1 [L,NC]
    RewriteRule ^announcements$ ./announcements.php [L,NC]
     
    # Downloads
    RewriteRule ^downloads/([0-9]+)/([^/]*)$ ./downloads.php?action=displaycat&catid=$1 [L,NC]
    RewriteRule ^downloads$ ./downloads.php [L,NC]
     
    # Knowledgebase
    RewriteRule ^knowledgebase/([0-9]+)/[a-z0-9_-]+\.html$ ./knowledgebase.php?action=displayarticle&id=$1 [L,NC]
    RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ ./knowledgebase.php?action=displaycat&catid=$1 [L,NC]
    RewriteRule ^knowledgebase$ ./knowledgebase.php [L,NC]

 



WordPress

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress

 



WordPress MultiSite

RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
     
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
     
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
     
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]





WordPress Supercache

# BEGIN WPSuperCache
    RewriteEngine On
    RewriteBase /
     
    #If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible
    AddDefaultCharset UTF-8
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{HTTPS} on
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]
     
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{HTTPS} !on
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz" [L]
     
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTPS} on
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html" [L]
     
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTPS} !on
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html" [L]# END WPSuperCache

 



Drupal

#
    # Apache/PHP/Drupal settings:
    #
     
    # Protect files and directories from prying eyes.
    <filesmatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|entries.*|repository|root|tag|template)$"="">
      Order allow,deny
     
    # Don't show directory listings for URLs which map to a directory.
    Options -Indexes
     
    # Follow symbolic links in this directory.
    Options +FollowSymLinks
     
    # Customized error messages.
    ErrorDocument 404 /index.php
     
    # Set the default handler.
    DirectoryIndex index.php
     
    # Override PHP settings. More in sites/default/settings.php
    # but the following cannot be changed at runtime.
     
    # PHP 4, Apache 1.
      php_value magic_quotes_gpc                0
      php_value register_globals                0
      php_value session.auto_start              0
      php_value mbstring.http_input             pass
      php_value mbstring.http_output            pass
      php_value mbstring.encoding_translation   0
     
    # PHP 4, Apache 2.
      php_value magic_quotes_gpc                0
      php_value register_globals                0
      php_value session.auto_start              0
      php_value mbstring.http_input             pass
      php_value mbstring.http_output            pass
      php_value mbstring.encoding_translation   0
     
    # PHP 5, Apache 1 and 2.
      php_value magic_quotes_gpc                0
      php_value register_globals                0
      php_value session.auto_start              0
      php_value mbstring.http_input             pass
      php_value mbstring.http_output            pass
      php_value mbstring.encoding_translation   0
     
    # Requires mod_expires to be enabled.
      # Enable expirations.
      ExpiresActive On
     
      # Cache all files for 2 weeks after access (A).
      ExpiresDefault A1209600
     
      # Do not cache dynamically generated pages.
      ExpiresByType text/html A1
     
    # Various rewrite rules.
      RewriteEngine on
     
      # If your site can be accessed both with and without the 'www.' prefix, you
      # can use one of the following settings to redirect users to your preferred
      # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
      #
      # To redirect all users to access the site WITH the 'www.' prefix,
      # (http://example.com/... will be redirected to http://www.example.com/...)
      # adapt and uncomment the following:
      # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
      # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
      #
      # To redirect all users to access the site WITHOUT the 'www.' prefix,
      # (http://www.example.com/... will be redirected to http://example.com/...)
      # uncomment and adapt the following:
      # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
      # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
     
      # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
      # VirtualDocumentRoot and the rewrite rules are not working properly.
      # For example if your site is at http://example.com/drupal uncomment and
      # modify the following line:
      # RewriteBase /drupal
      #
      # If your site is running in a VirtualDocumentRoot at http://example.com/,
      # uncomment the following line:
      # RewriteBase /
     
      # Rewrite URLs of the form 'index.php?q=x'.
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]# $Id: .htaccess,v 1.90 2007/10/05 14:43:23 dries Exp $

 



Joomla

##
    # @package    Joomla
    # @copyright  Copyright (C) 2005 - 2014 Open Source Matters. All rights reserved.
    # @license    GNU General Public License version 2 or later; see LICENSE.txt
    ##
     
    ##
    # READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    ##
     
    ## Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
     
    ## Mod_rewrite in use.
     
    RewriteEngine On
     
    ## Begin - Rewrite rules to block out some common exploits.
    # If you experience problems on your site block out the operations listed below
    # This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    # Block out any script trying to base64_encode data within the URL.
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a script tag in URL.
    RewriteCond %{QUERY_STRING} (<|<)([^s]*s)+cript.*(>|>) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL.
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL.
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ## End - Rewrite rules to block out some common exploits.
     
    ## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
    ## End - Custom redirects
     
    ##
    # Uncomment following line if your webserver's URL
    # is not directly related to physical file paths.
    # Update Your Joomla! Directory (just / for root).
    ##
     
    # RewriteBase /
     
    ## Begin - Joomla! core SEF Section.
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for something within the component folder,
    # or for the site root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ## End - Joomla! core SEF Section.

 



LiveSite

# The following rules are used by liveSite.
     
     
     
    RewriteEngine on
     
     
     
    # The following rule enables search engine friendly URL's for Pages.
     
    RewriteRule ^pages/(.*) /livesite/get_page.php?page=$1&%{QUERY_STRING}
     
     
     
    # The following rule enables search engine friendly URL's for Files.
     
    RewriteRule ^files/(.*) /livesite/get_file.php?name=$1
     
     
     
    # The following rule enables the robots.txt file which helps search engines crawl a website.
     
    RewriteRule ^robots\.txt$ /livesite/get_robots.txt.php
     
     
     
    # The following rule enables the sitemap.xml file which helps search engines find content.
     
    RewriteRule ^sitemap\.xml$ /livesite/get_sitemap.xml.php

 



PrestaShop

RewriteEngine On
    RewriteBase /prestashop/
     
    # ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
    # .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
    # http://www.prestashop.com - http://www.prestashop.com/forums
    SetEnv HTTP_MOD_REWRITE On
     
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule . - [E=REWRITEBASE:/prestashop/]
    RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
     
    # Images
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
    # AlphaImageLoader for IE and fancybox
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
     
    # Dispatcher
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^.*$ - [NC,L]
    RewriteCond %{HTTP_HOST} ^kool-story-bro.net$
    RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]#If rewrite mod isn't enabled
    ErrorDocument 404 /prestashop/index.php?controller=404
     
    # ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again 

 



Magento

     
    ############################################
    ## uncomment these lines for CGI mode
    ## make sure to specify the correct cgi php binary file name
    ## it might be /cgi-bin/php-cgi
     
    #    Action php5-cgi /cgi-bin/php5-cgi
    #    AddHandler php5-cgi .php
     
    ############################################
    ## GoDaddy specific options
     
    #   Options -MultiViews
     
    ## you might also need to add this line to php.ini
    ##     cgi.fix_pathinfo = 1
    ## if it still doesn't work, rename php.ini to php5.ini
     
    ############################################
    ## this line is specific for 1and1 hosting
     
        #AddType x-mapp-php5 .php
        #AddHandler x-mapp-php5 .php
     
    ############################################
    ## default index file
     
        DirectoryIndex index.php
     
    ############################################
    ## adjust memory limit
     
        php_value memory_limit 512M
        php_value max_execution_time 18000
     
    ############################################
    ## disable magic quotes for php request vars
     
        php_flag magic_quotes_gpc off
     
    ############################################
    ## disable automatic session start
    ## before autoload was initialized
     
        php_flag session.auto_start off
     
    ############################################
    ## enable resulting html compression
     
        #php_flag zlib.output_compression on
     
    ###########################################
    # disable user agent verification to not break multiple image upload
     
        php_flag suhosin.session.cryptua off
     
    ###########################################
    # turn off compatibility with PHP4 when dealing with objects
     
        php_flag zend.ze1_compatibility_mode Off
    ###########################################
    # disable POST processing to not break multiple image upload
     
        SecFilterEngine Off
        SecFilterScanPOST Off
     
    ############################################
    ## enable apache served files compression
    ## http://developer.yahoo.com/performance/rules.html#gzip
     
        # Insert filter on all content
        ###SetOutputFilter DEFLATE
        # Insert filter on selected content types only
        #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
     
        # Netscape 4.x has some problems...
        #BrowserMatch ^Mozilla/4 gzip-only-text/html
     
        # Netscape 4.06-4.08 have some more problems
        #BrowserMatch ^Mozilla/4\.0[678] no-gzip
     
        # MSIE masquerades as Netscape, but it is fine
        #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
     
        # Don't compress images
        #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
     
        # Make sure proxies don't deliver the wrong content
        #Header append Vary User-Agent env=!dont-vary
     
    ############################################
    ## make HTTPS env vars available for CGI mode
     
        SSLOptions StdEnvVars
     
    ############################################
    ## enable rewrites
     
        Options +FollowSymLinks
        RewriteEngine on
     
    ############################################
    ## you can put here your magento root folder
    ## path relative to web root
     
        #RewriteBase /magento/
     
    ############################################
    ## workaround for HTTP authorization
    ## in CGI environment
     
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
     
    ############################################
    ## always send 404 on missing files in these folders
     
        RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
     
    ############################################
    ## never rewrite for existing files, directories and links
     
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l
     
    ############################################
    ## rewrite everything else to index.php
     
        RewriteRule .* index.php [L]
     
     
    ############################################
    ## Prevent character encoding issues from server overrides
    ## If you still have problems, use the second line instead
     
        AddDefaultCharset Off
        #AddDefaultCharset UTF-8
     
    ############################################
    ## Add default Expires header
    ## http://developer.yahoo.com/performance/rules.html#expires
     
        ExpiresDefault "access plus 1 year"############################################
    ## By default allow all access
     
        Order allow,deny
        Allow from all
     
    ############################################
    ## If running in cluster environment, uncomment this
    ## http://developer.yahoo.com/performance/rules.html#etags
     
        #FileETag none
  • 45 Users Found This Useful
Was this answer helpful?

Related Articles

Is it a problem if I'm not in the US?

Not at all! In fact, we already have customers in countries all over the world.

I uploaded my page but it's not working!

Make sure that you are uploading to the public_html or www folder.  Only the files placed...

What is an error 404 page?

Error 404 indicates that you are requesting a file or a directory that does not exist on the...

Can I run scripts like Wordpress, Joomla, or phpBB on my site?

Absolutely! We make it extremely easy to install over 250 different scripts via the Softaculous...

Can I upgrade my plan or features later?

Upgrades/Addons are available to purchase at any time through your Client Area dashboard. Once...