重写相对路径的规则?

时间:2013-08-18 03:57:25

标签: apache mod-rewrite

我得到的浏览器错误是:

The requested URL /home/user/public_html/some_folder was not found on this server.

apache日志是:

[Sat Aug 17 20:57:57 2013] [error] [client ] File does not exist: /var/www/html/home

我觉得很自然,我会尝试RewriteBase /../../../home/user/public_html/,但这会让我:

[Sat Aug 17 20:59:22 2013] [error] [client ] Invalid URI in request GET /~user/ HTTP/1.1

我该如何解决这个问题?

.htaccess很简单:

RewriteEngine On

RewriteBase /../../../home/user/public_html/

RewriteRule  index.php                 some_folder/index.html  [L]

1 个答案:

答案 0 :(得分:0)

您可以使用符号链接。

cd /var
cp /var/www /var/backup_www
rm -rf /var/www
ln -s /home/user/public_html/ www

在httpd.conf中启用以下符号链接。

<Directory /var/www>
    Options FollowSymLinks
</Directory>

<Directory /home/user/public_html>
    Options -FollowSymLinks
</Directory>

或者,只需更改服务器/虚拟主机的DocumentRoot。