【发布时间】:2012-06-07 19:56:10
【问题描述】:
我遇到了 apaches mod_rewrite 的问题。我想用我的 php 应用程序创建干净的 url,但它似乎没有给出我期望的结果。
我在我的 .htaccess 文件中使用此代码:
RewriteEngine on
RewriteRule ^project/([0-9]{4})/([0-9]{2})$ /project/index.php?q=$1&r=$2 [L]
RewriteRule ^project/([0-9]{4})$ /project/index.php?q=$1 [L]
这样当我查看http://localhost/user/project/system 时,就相当于查看http://localhost/user/project/index.php?q=system
我没有得到任何结果,而是得到一个典型的 404 错误。
我还刚刚检查了 mod_rewrite 是否可以通过将我的 .htaccess 代码替换为以下代码:
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) http://www.stackoverflow.com
它正确地将我重定向到这里,所以 mod_rewrite 肯定是有效的。
我的项目的根路径是/home/user/public_html/project
用于查看我的项目的网址是http://localhost/user/project
如果需要更多信息,请告诉我。
谢谢
【问题讨论】:
-
如果删除目标路径中的前导
/会发生什么? -
.htaccess 文件在哪里?如果已经在 project/ 文件夹中,则在 RewriteRule 中提及它将不起作用。
-
@Emil - 据我所知,什么都没有。
-
@mario - 是的,我该怎么办?
标签: php apache mod-rewrite