用mod_rewrite重写基本URL

我的域example.com指向public_html目录。 在目录public_html / php是我的index.php文件。

现在我希望URL example.com指向public_html / php / index.php 。 我必须用mod_rewrite来做这件事,因为我没有访问httpd.conf来做别名或者DocumentBase。

在目录public_html是我的.htacces文件具有以下内容:

RewriteEngine on RewriteCond %{HTTP_HOST} exaple.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /php/index.php [L,QSA] 

这样做的一半,因为当我在我的浏览器中input像example.com/s的东西,它指向public_html / php / index.php,因为我希望它做。 但是,当我刚刚进入example.com它指向public_html

我能做些什么来解决这个问题?

 RewriteCond %{REQUEST_FILENAME} !-f 

!-f标志表示“如果请求的文件不存在”。 访问example.com时,Apache DirectoryIndex指令将请求redirect到/public_html/index.php ,该文件是否存在? 因为如果这样做,你的RewriteRule被忽略。 你必须删除上面的RewriteCond ,或者删除/public_html/index.php文件。