使用mod_rewrite将index.html重写到cgi-bin文件夹中

基本上,PHP只能在我的主机的cgi-bin文件夹中执行。

在我的web空间中,我的index.html文件path如下所示:

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

当用户input时,我想要一个mod_rewrite来:

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

什么是mod_rewrite代码来做到这一点? 我试了一堆东西,它不工作。 我认为这也可能与index.html ACTUALLY有以下path(这是我必须去使用UNIX命令):

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

但是,www.example.edu/~username/index.html带我到WWW文件夹中的index.html

这是我的.htaccess文件:

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> 

你想redirect或重写的URL? 如果redirect浏览器的URL栏地址将会改变。 你可以这样做:

 Redirect /index.html http://www.example.edu/~username/cgi-bin/index.php 

如果你想重写它,所以用户不会看到PHP URL,如下所示:

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

查询string(例如?foo=bar )将被传递给PHP脚本。 [L]意思是“最后” – 不要处理任何以下规则。

编辑:

你可以肯定使用mod_rewrite ? 尝试删除你的< IfModule >行,看看你是否得到一个错误(你会看到一个500,如果该模块不会加载或未加载)。

并尝试:

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

这将强制302redirect,更改您的浏览器URL。 这应该显示你mod_rewrite的值是用来replace的。