如何让mod_rewrite在我的主目录中工作?

时间:2009-11-05 20:21:14

标签: php apache freebsd

我的PHP文件存放在FreeBSD下的这个目录下:

/home/david/public_html/code/php

在我的浏览器中,我通过以下网址访问它们:

http://192.168.6.7/~david/code/php

我有一个htaccess文件来重写URL:

RewriteEngine on
RewriteRule ^test test.php

但是当我在浏览器中转到http://192.168.6.7/~david/code/php/test时,我收到此错误:

Not Found

The requested URL /home/david/public_html/code/php/test.php

如您所见,重写规则成功尝试将测试重定向到test.php。但由于某种原因,它失败了。

我在我的apache错误日志文件中找到了这个:

File does not exist: /usr/local/www/data/home

任何人都知道如何解决这个问题? 顺便说一下,如果我把它放在一个web目录而不是我的主目录中,一切正常。

1 个答案:

答案 0 :(得分:5)

使用RewriteBase将基本网址路径设置为/~david/code/php/

RewriteBase /~david/code/php/

您还应明确将UseDir设置为public_html。另请参阅Per-user web directories in the Apache manual

相关问题