Forgot your password?

xtreemhost

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} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

Once you have done so, both mydomain.com and www.mydomain.com will send you to www.mydomain.com

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} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

This will make both mydomain.com and www.mydomain.com send you to mydomain.com.

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 123.45.6.7
deny from 012.34.5.
allow from all

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

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

    Thanks

  • 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 example:mydomain.cu.cc/fansons.php?id=1 into mydomain.cu.cc/usernamebut it doens’t work, so i need your help so muchthanks

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

Archives