1

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>
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.

  • 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 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"; ?> – Tony Stark Aug 4 '09 at 9:50
  • yea, foo.html rewrite didn't work. guess i'm stuck using a dumb redirect :( – Tony Stark Aug 4 '09 at 9:52
  • It's not so bad. At least it's obvious! – markdrayton Aug 4 '09 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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