Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried using the following rule:

RewriteEngine On
RewriteRule ^(.*)$ /~user/sub/index.cgi [L]

but I am getting an error. This is intended to redirect all requests within my sub/ subdirectory (which is in a web docs on a server) to a single script, but it is not working. What would the correct rule be?


share|improve this question


RewriteEngine On
RewriteRule ^(.*)$ sub/index.cgi [L]

Assuming that this .htaccess file is in the root of your ~user directory.

For example, username jay:

Home directory: /home/jay
Web directory:  /home/jay/public_html (http://something/~user points here)
.htaccess file: /home/jay/public_html/.htaccess
script:         /home/jay/public_html/sub/index.cgi

Based on your comment, if your .htaccess file is in the sub directory, then you only need:

RewriteEngine On
RewriteRule ^(.*)$ index.cgi [L]
share|improve this answer
It's not, it's in the sub/ subdirectory. (edited to clarify) – Peter Oct 11 '12 at 18:25
Then you just need to do index.cgi with nothing else. – Jay Oct 11 '12 at 18:26
That does not seem to work. :( Specifically, I get a 404 error. So it is redirecting...but it must not be redirecting to the right place. – Peter Oct 11 '12 at 18:30
Then it's time to get debugging. A really easy way: make your .htaccess file garbage, do you get a 500 Internal Server Error? If not, your .htaccess is not being read at all. If you get the error, you'll need to check your httpd.conf for AllowOverride. – Jay Oct 11 '12 at 18:35
It is being used. I get a 500 internal server error with a bad .htaccess. And the 404 goes away when i point to an HTML file after disabling the .htaccess, but the 404 returns when I re-enable it, meaning it is being redirected after all. Just to the wrong place. Double checked spelling--index.cgi is the correct file. – Peter Oct 11 '12 at 18:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.