我正在使用 mod_rewrite 和 .htacces 文件设置一些简单的 url 重写规则,但我遇到了一些问题。 如果我这样设置 .htacces:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule /index.html /index.php [L]
当我从浏览器调用这个 url 时: 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 页面。 我是否被迫使用绝对 url 作为重写的目标?这是 Apache 配置问题吗?
我正在使用 Max OS X 10.6.2 及其标准 Apache 安装。
最佳答案
RewriteBase 基本指令正在设置基本路径;您不需要在重定向规则中提供绝对路径。
规则模式不是纯文本;这是一个正则表达式。
如果您将完整的 URL 设置为目标,您会指示浏览器重定向到该其他位置;这种重定向对用户来说不是透明的。
总结一下,试试这个:
RewriteRule ^index\.html$ index.php [L]
关于apache - mod_rewrite 和相对 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2401022/