mod_rewrite和相对网址

时间:2010-03-08 11:49:38

标签: apache .htaccess mod-rewrite

我正在使用mod_rewrite和.htacces文件设置一些简单的url重写规则,但是我遇到了一些问题。 如果我以这种方式设置.htacces:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

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

当我从浏览器调用此网址时: http://localhost/~dave/mySite/index.html 我收到了404错误。

使用此.htacces代替

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteRule /index.html http://localhost/~dave/mySite/index.php [L]

一切正常,我得到了我期待的index.php页面。 我是否被迫使用绝对网址作为重写的目标?这是Apache配置问题吗?

我正在使用Max OS X 10.6.2及其标准的Apache安装。

2 个答案:

答案 0 :(得分:4)

  1. RewriteBase基本指令正在设置基本路径;您不需要在重定向规则中提供绝对路径。

  2. 规则模式不是纯文本;这是一个正则表达式。

  3. 如果您将完整网址设置为目标,则会指示浏览器重定向到其他位置;这种重定向对用户来说是不透明的。

  4. 总结一下,试试这个:

    RewriteRule ^index\.html$ index.php [L]
    

答案 1 :(得分:0)

尝试

RewriteRule ^(.*)/index.html $1/index.php [L]

应该对它进行排序。