ULIX TxT Editor on Sourceforge.net






Sample .htaccess file


This is a sample htaccess file, and this is what the htaccess file looks like after following the steps shown above. Its really easy to follow and understand if you've followed everything up to this point.



.htaccess File Example


# DO NOT MODIFY THIS SECTION
<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"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

# DO NOT MODIFY THIS SECTION
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Main RewriteRule (This section Can be modified)
RewriteRule ^/?$ /home [R=302,L]
RewriteRule ^$ /home [R=302,L]
RewriteRule ^home$ /index.html [L]

RewriteRule ^en/help/ContactMe$ /contact.html [L]

# Reverse the last example to work in opposite direction
RewriteRule ^index$ /en/2015/April/index.php [L]

# Please note that you cannot use the permanent and temporary redirect values on the same link.
# Create a page Redirect [Permanent Redirect]

RewriteRule ^about$ /home.php [R=301,L]

# Create a page Redirect [Temporary Redirect]
RewriteRule ^about$ /home.html [R=302,L]

# Please note that you cannot use the Options -Index value in conjuction with the Options +Indexes values.
# Make your folders private

Options -Indexes

# Make your folders visible to everyone
# Options +Indexes


# Redirect direct HP and Domain access to an HTTPS/SSL name
# This also works well as redirecting the whole site to a new domain name

RewriteCond %{HTTP_HOST} ^yourdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteRule ^/?$ https://yourdomain.com/pageofchoice [R=301,L]
RewriteRule ^$ https://yourdomain.com/pageofchoice [R=301,L]

# IP Detection and redirection to appropriate domain/country site
# Redirect all IP address (replace the ## with the IP address # numerals) to same http://yourdomain.ca
RewriteCond %{HTT_HOST} ^##\.##\.##\.##
RewriteRule (.*) http://yourdomain.ca/$1 [R=301,L]

# Block multiple IP addresses using Deny from
## for listings of multiple IPs from an entire country, Google "Country IP Listings"
### Or go to http://www.parkansky.com/china.htm for full list
order allow,deny
allow from all
deny from 65.19.146.2 220.248.0.0/14
#### The above deny from argument is only a sample.
##### To get all known spam and ip hacker locations,
######please download the full.htaccess file from the link below.

# This section below is for overwriting all pages
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/hiatus\.php$
RewriteRule ^(.*)$ /Hiatus [R=302,L]

# Make your folders read specific PHP Versions
AddHandler application/x-httpd-php55 .php .php5 .php4 .php3

# Simple Password Protected file
# Restricted Access

AuthUserFile /home/username/.htpasswds/public_html/passwd
AuthName "RESTRICTED AREA"
AuthType Basic
<files "filename.php">
Require valid-user
</files>


Need a copy of this file for your personal use? Download a sample copy here.
Need a copy of this file, with IP blocks pre-inserted, for your personal use? Download a full copy here.