【问题标题】:.htaccess mod_rewrite rule not working in Ubuntu.htaccess mod_rewrite 规则在 Ubuntu 中不起作用
【发布时间】:2009-11-07 05:17:11
【问题描述】:

如果这很简单,我深表歉意。我已经用谷歌搜索了它,但无济于事。

我正在运行 Ubuntu 9.04、Jaunty Jackelope 和 Apache2。经过很多麻烦,我终于启用 mod_rewrite,我的 .htaccess 文件正在尝试做这件事,但失败了。这是我的设置。

在 /etc/apache2/conf.d/ 我有一个名为 apeace-public-html.conf 的文件。内容如下:

# makes /home/apeace/public_html/ available through /localhost/apeace

Alias /apeace /home/apeace/public_html/

在 /home/apeace/public_html/ 我有以下 .htaccess 文件:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^test\.html$ index.html

另外在 /home/apeace/public_html/ 我有一个名为 index.html 的文件,但我没有一个名为 test.html 的文件。在我看来,当我尝试访问 http://localhost/apeace/test.html 时,这个重写应该显示 index.html。但是,这是我得到的错误:

Not Found

The requested URL /home/apeace/public_html/index.html was not found on this server.

所以问题是,我到底做错了什么?

非常感谢。

-和平

【问题讨论】:

    标签: apache mod-rewrite ubuntu


    【解决方案1】:

    这里只是一个猜测,但是你能不能试着把 RewriteRule 写成 ^test.html$ /apeace/index.html

    从错误消息看来,它似乎正在将`http://localhost/apeace/test.html 翻译成http://localhost/home/apeace/public_html/index.html

    【讨论】:

    • 这行得通。太感谢了。我不敢相信事情就这么简单。
    【解决方案2】:

    您的重写规则运行正常,因为它告诉您找不到“index.html”。如果您访问 test.html 并且它说找不到“test.html”,那么您的重写规则就会出错。

    所以这意味着您的设置中有其他问题,无论是某处的错误文件或目录名称,还是其他任何问题。确保您没有忽略任何基本内容。

    但在回答您的问题(尤其是标题)时,您的 htaccess 很好。

    【讨论】:

    • 对不起,我不够清楚:P 我的意思是访问 /test.html 并获得 /index.html,因为 index.html 存在而 test.html 不存在。然而,事实证明,另一位先生的回答是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多