Forcing all requests from one domain name to go to another (and update address bar)

This is a mod_rewrite recipe that will force all requests for your hosting account to be
redirected to a particular domain.

Here’s an example:

You have,,

on your account. You would like requests for any of the domain names to go to:

and to update the address bar in the browser to reflect this.

Here’s how to do it :

Create a .htaccess file in your top web directory (the directory www for most users)

put the following lines in it:

RewriteEngine On

# this will force all domain requests to go to
RewriteCond %{HTTP_HOST} !^
rewriterule (.*)$1 [R=permanent,L]

My site is showing a list of all my files! How do I control directory indexes?


My site is showing a listing of all my files. Anyone who comes to my website can see everything! Help!


The directory index is showing because you have no index.html file. Anytime there is no index.html (or index.php, index.htm, etc.) the server will show the default index that it creates on the fly.

You can also control the automatic creation of indexes by performing the following steps :

Create (or edit your existing) .htaccess file and put it in the topmost directory that you want to control. To enable / disable for your whole site, put it in your www directory.

To disable directory listings, add the line :

Options -Indexes

To enable them, add the line :

Options +Indexes

If your site still does not list the directory after enabling and you get the error :

“Forbidden You don’t have permission to access / on this server.”

make sure the read privilege is set for the directory you have the .htaccess file in.

Can I deny / ban an IP address from accessing my website?


I have collected the IP addresses of some people who have been causing problems on my website. Would you be able to tell me if they use dynamic or static IPs? Is there are way to block these IP addresses to my site?



There is no quick and easy way to tell if they are using dynamic or static IPs. You can research each IP and sometimes get an idea from the reverse lookup name. Even then it can be hard to tell.

Blocking, banning, etc. the IPs is easy though.

Here is how to block them from your site :

Create a file called


(that is dot htaccess – the file begins with a dot)

If you are having a hard time creating a file that starts with a dot, you can create the file as any filename, upload it to your server and then rename it in FTP to be .htaccess. The file will only work if it is called .htaccess (dot htaccess).

Inside the .htaccess file put these lines:

Order Allow,Deny
Deny from
Allow from all

Replace the address above ( with the actual address you are wanting to ban.

Next add a seperate :

Deny from

line for each IP you want to deny.

If you want to block a range of IPs you can do this :

Deny from 192.168.1.

which would block everything in the 192.168.1.x range. For example:

I hope this helps you!

Do you support mod_rewrite?

Yes, mod_rewrite is fully supported. mod_rewrite is a great apache module and we are happy to allow its use.

You can enter mod_rewrite rules into a standard .htaccess file. The rules will have effect over all files in that directory and in all directories “below” that directory.

Please note that due to the complex nature of mod_rewrite rules, we are not able to offer debugging assistance with your rules.

I’d like to run cgi’s from anywhere in my site – not just the cgi-bin directory.

Question :

I’d like to run cgi’s from anywhere in my site – not just the cgi-bin directory.

Answer :

Create a .htaccess file and add the lines:

AddHandler cgi-script .pl
AddHandler cgi-script .cgi

to it.

Add other AddHandler statements if you are using different file extensions.

Can I point a subdomain to a cgi script?

Can I point a sub domain at a cgi script?


A subdomain in DNS can only point to an IP. A full URL (ie. a script) is above the level of DNS. DNS only understands
IP’s and domain names. Not full URLs.

You can use the 403 redirect option to have the webserver forward the subdomain request to the URL.

Another approach is to point the subdomain to a sub-directory in the control panel and then have that sub-directory’s index page immediately redirect to your cgi script. You could also use .htaccess to make the filename for your script be one of the index pages.