Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Basically, php can only be executed in my host's cgi-bin folder.

In my webspace, my index.html file path looks like this:

When a user types that, I would like a mod_rewrite to:

What is the mod_rewrite code to do that? I've tried a bunch of things and it doesn't work. I think it might also have to do with the index.html ACTUALLY having the following path (this is what I have to go to using unix commands):

However, takes me to the index.html within the WWW folder

Here is my .htaccess file:

LoadModule rewrite_module modules/
AddModule mod_rewrite.c

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/index.html$ /cgi-bin/index.php [L]
share|improve this question
up vote 3 down vote accepted

Do you want to redirect or rewrite the URL? If you redirect the browser's URL bar address will change. You can do this with:

Redirect /index.html

If you want to rewrite it, so the user doesn't see the PHP URL, something like:

RewriteEngine On
RewriteRule ^/index.html$ /cgi-bin/index.php [L]

The query string (eg ?foo=bar) will be passed through to the PHP script. [L] means 'last' -- don't process any following rules.


Can you definitely use mod_rewrite? Try removing your <IfModule> lines and see if you get an error (you'd see a 500 if the module won't load or isn't loaded).

And try:

RewriteRule ^/index.html$ /cgi-bin/index.php [L,R=302]

This'll force a 302 redirect, changing your browser URL. This should show you the value mod_rewrite is for the replacement.

share|improve this answer
ah yeah thanks i want to rewrite, NOT redirect – sepiroth Aug 4 '09 at 9:46
i don't see 500 anywhere, but removing IfModule just gives me the same error (i just see the same error i always get - 'Server Error: The server encountered an internal error and was unable to complete your request. There was an error in your CGI script.') – sepiroth Aug 4 '09 at 9:48
Aha. Sounds very like you can't use mod_rewrite. Try "RewriteRule ^/foo.html$ /index.html [R]" and hit /foo.html. If it fails with server error you can't use mod_rewrite; if the browser goes to /foo.html you can use it but something else is up with your original problem. – markdrayton Aug 4 '09 at 9:49
also, adding R=302 didn't do anything (same error). also, i highly doubt there is an error in my php script: <?php echo "test"; ?> – sepiroth Aug 4 '09 at 9:50
yea, foo.html rewrite didn't work. guess i'm stuck using a dumb redirect :( – sepiroth Aug 4 '09 at 9:52

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.