ULIX TxT Editor on Sourceforge.net

How to create a .htaccess file

When creating an htaccess file simply follow these steps.

1. Expiration Headers

Always start your file with an Expiration Header
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 year"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"

2. Inserting RewriteRules

The next step is to add a RewriteEngine rule needed to make www.yourdomain.com/index.html work as www.yourdomain.com/index
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

Now insert the RewriteRule code for the page you wish to have the way it is accessed changed
# Main RewriteRule (This section Can be modified)
RewriteRule ^/?$ /home [R=302,L]
RewriteRule ^$ /home [R=302,L]
RewriteRule ^home$ /index.html [L]

3. Folder Rewrites

Have a file that is not found in a folder appear as though it is
RewriteRule ^en/help/ContactMe$ /contact.html [L]
Have a file that IS in a folder appear as though it's in another folder
RewriteRule ^en/HelpCenter/Bugs$ /help/center/bug-report.html [L]
Have a file that is located in a folder appear as though it is not
RewriteRule ^index$ /en/2015/April/index.php [L]

4. Open and Closed Folder access

Please note that example A and B can not be used at the same time, one or the other. Otherwise you will get a 500 Internal Server Error.

A. Make your folders private
#Make your folders private
Options -Indexes

B. Make your folders non-private
# Make your folders visible to everyone
Options +Indexes

5. Inserting a comment

To create a comment, simply place a # in-front of the phrase you wish for the server to ignore
# This is a comment
RewriteRule ^this-is-not-a-comment$ /whateveryounameit.html [L]

6. PHP Version Compatability Control

Make sure that all php versions are compatible with your website
AddHandler application/x-httpd-php55 .php .php5 .php4 .php3