HostMonster Web Hosting Help


What is mod_rewrite?

Mod Rewrite allows you to change the URL that everyone sees when they visit your domain or a specific address. Just add the code to your .htaccess file (typically the one inside public_html).

Please remember we do not offer support to code this, nor do we promise to make your code work. Some of these codes work in combination, and some do not.


#Specify a default home page (index page)
DirectoryIndex home.html

#Allow only specified IPs to access your site
deny from all
allow from
allow from

# Redirect all pages from
# to
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [R=301,L]

#Prevent subfolder loading. This goes
# in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^*)$ "$1" [R=301,L]

#Prevent subdomain name loading.
#This goes in htaccess for the primary domain
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ "$1" [R=301,L]

# Never use www in the domain
# Replace '' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

# Always use www in the domain
# Replace '' with your domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?$ [NC]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .?{REQUEST_URI} [R=301,L]

# Set a default home directory, (this subfolder always loads)
# Replace 'folder' with your subfolder name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /folder/ [R=301,L]

# Rename a directory and force visitors to the new name
# Replace 'old' with your old folder name
# Replace 'new' with your new folder name
RewriteEngine on
RewriteRule ^/?old([a-z/.]*)$ /new$1 [R=301,L]

# Always use https for secure connections
# Replace '' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]

# Block traffic from multiple referrers
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} [NC,OR]
RewriteCond %{HTTP_REFERER} [NC,OR]
RewriteCond %{HTTP_REFERER} [NC]
RewriteRule .* - [F]

#Do not allow these file types to be called
RewriteEngine on
RewriteRule .*.(jpg|jpeg|gif|png|bmp|exe|swf)$ - [F,NC]

Guides to dot-htaccess coding:

Knowledgebase Article 111,030 views bookmark tags: apache mod rewrite (updated 983 days ago)

Was this resource helpful?

Did this resolve your issue?

Please add any other comments or suggestions about this content:

Recommended Help Content

Preventing bandwidth theft using the mod rewrite engine and .htaccess (updated 1176 days ago)
Knowledgebase Article 104,067 views tags: htaccess rewrite

This article will explain how to use Easy Apache to recompile Apache. This is useful if you want to change the version of PHP or change other PHP and Apache settings. (updated 141 days ago)
Knowledgebase Article 1,799 views tags: apache build compile dedi dedicated easy modules version vps

Virtual directory support for PHP. (updated 2157 days ago)
Knowledgebase Article 67,426 views tags: directory php support

Related Help Content

How do I perform a URL redirect/rewrite using the .htaccess file? (updated 220 days ago)
Knowledgebase Article 736,463 views tags: htaccess redirect rewrite url

What are Apache Handlers? How do I setup customized Apache Handlers? (updated 175 days ago)
Knowledgebase Article 69,700 views tags: apache handler handlers

Hard refresh after changing the .htaccess (updated 970 days ago)
Knowledgebase Article 53,569 views tags: apache

What types of technical support do you offer me? (updated 162 days ago)
Knowledgebase Article 64,861 views tags: chat email phone support technical

Does HostMonster supoprt FFMPEG support. (updated 896 days ago)
Knowledgebase Article 71,267 views tags: encoding ffmpeg flash flv flvtools module path perl support video

The redirection of or index.html to redirects it to In other words, (updated 616 days ago)
Knowledgebase Article 723,759 views tags: htaccess messing mod php redirect redirects rewrite variable variables

Changing PHP versions, load custom Apache mods, and other Apache/PHP customizations (updated 566 days ago)
Knowledgebase Article 12,365 views tags: easyapache php vps whm

How do I use .html files to run SSI (Server Side Includes)? (updated 1898 days ago)
Knowledgebase Article 163,070 views tags: apache file script