Mod_rewrite 无法正常工作
我的 .htaccess
文件中有这个...
RewriteEngine on
RewriteRule ^/invite$ /invite.html
它的目的是让用户访问此 url:
http://mysite.com/invite
并显示 invite.html
页面。我不想重定向用户,只是向他们显示来自更好看的 URL 的 invite.html
页面。
但是,当我浏览到 http://mysite.com/invite
时,我收到 404 未找到错误。
我做错了什么吗?我尝试查看使用 mod_rewrite 的教程,但我似乎也在做他们告诉我的事情......
谢谢!
I have this in my .htaccess
file...
RewriteEngine on
RewriteRule ^/invite$ /invite.html
It's meant to let a user access this url:
http://mysite.com/invite
and display the invite.html
page. I don't want to redirect the user, but just show them the invite.html
page from a better looking URL.
When I browse to http://mysite.com/invite
though, I get a 404 not found error.
Is there anything I'm doing wrong? I've tried looking at tutorials for using mod_rewrite but I seem to be doing what they're telling me too...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为
RewriteRule
中不应该有/
:I don't think there should be a
/
in thatRewriteRule
:您是否确保为 .htaccess 文件所在的目录设置了
AllowOverride All
?否则该文件可能会被忽略。如果不是这种情况,您应该查看 Apache 的日志文件以获取更多提示(Linux 上为
/var/log/apache
)。Did you make sure that
AllowOverride All
is set for the directory where the .htaccess file lies? Else the file might be ignored.If this isn't the case, you should check out Apache's log files for more hints (
/var/log/apache
on Linux).您缺少 RewriteCond 指令。这是执行实际测试
条件
来匹配 URL 的方法。仅当一个或多个 RewriteCond 匹配时才会调用 RewriteRule。You're missing a RewriteCond directive. That's the one that does the actual testing
Cond
ition to match a URL. The RewriteRule is invoked only when one or more RewriteConds are matched.