Forgot your password?


5 Popular .htaccess Tips & Tricks

There are tons of things you can do from the .htaccess file inside of your xtreemhost web hosting account: from redirecting the users to controlling who can get in and who can get out etc. It is a very useful file to have in your hosting account. To help out the new xtreemhost clients and to act as a reminder to the old pros around here, we thought we would go through five of the most popular .htaccess tips we know.

1. Redirect to a maintenance page

This is a great one to use if you need to make some quick web page edits, and you don’t want the public to see you edit your web site, while it is still live.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/offline.html$
RewriteRule .* /offline.html [R=307,L]

This will redirect anybody who checks out any web page on your web site to the “offline.html” file.

2. Force the use of “www” in front of your domain

If you want to keep the www in front of your domain name, no matter how somebody types it in, here is the bit of .htaccess magic you need:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

Once you have done so, both and will send you to

3. Remove the “www” in front of your domain

You can also force your domain to drop the www from the address when typed in, if you would rather have it the other way around. In that situation, you would need to add this to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

This will make both and send you to

4. Manually create custom error pages

Ever check out some of those customized error pages and wonder how it could be done? Just use these snippets of .htaccess code to tell people where to look for your error pages.

ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

This tells the server to look inside the folder called “errors” and that specific page for each of the different error types. That is not all of the error codes, but they are the ones that will be hit by your users 99 percent of the time.

5. Block visitor by IP Address

Need to keep somebody from checking out your web site? This next tip will give you the ability to deny somebody based on what their IP address is:

order allow,deny
deny from
deny from 012.34.5.
allow from all

The above blocks access to the site from and from any sub-domain under the IP block 012.34.5. (eg.,,, etc).

This entry was posted in News. Bookmark the permalink.
  • Carlos Andres Cuevas Carvajal


  • Thank you for share!

  • pranshu

    Can we edit .htaccess file in the free account

  • xtreemhost

    Yes, you can edit / create a .htaccess file on free hosting.

  • rio

    i want to use htaccess for changing my url site for into it doens’t work, so i need your help so muchthanks

  • can i use php version 5.3 in free account ? if yes how ?