2

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

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

www.example.edu/~username/index.html

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

www.example.edu/~username/cgi-bin/index.php

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):

www.example.edu/~username/WWW/index.html

However, www.example.edu/~username/index.html takes me to the index.html within the WWW folder

Here is my .htaccess file:

LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/index.html$ /cgi-bin/index.php [L]
</IfModule>

1 Answers1

3

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 http://www.example.edu/~username/cgi-bin/index.php

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.

EDIT:

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.

markdrayton
  • 2,449
  • 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.') – Tony Stark Aug 04 '09 at 09: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 04 '09 at 09:49
  • also, adding R=302 didn't do anything (same error). also, i highly doubt there is an error in my php script: – Tony Stark Aug 04 '09 at 09:50
  • yea, foo.html rewrite didn't work. guess i'm stuck using a dumb redirect :( – Tony Stark Aug 04 '09 at 09:52
  • It's not so bad. At least it's obvious! – markdrayton Aug 04 '09 at 10:04