重写规则在 apache 1.3 中不起作用
我正在使用一些以前在 apache2 上始终有效的重写指令,但现在尝试新的共享主机,并且重写规则似乎没有得到应用。
我已将 .htaccess 文件简化为以下基本规则:
RewriteEngine On
Rewritebase /demo/
RewriteRule ^(.*)$ index.php/$1 [L]
如您所见,我想从根目录重写对 demo 文件夹中的 index.php 文件的每个请求。
所以一切都像 http://www.example.com/demo/albums/show/1 应由 http://www.example.com/demo/index 处理。 php 用于标准 MVC 设置。 (顺便说一句,我正在使用 CodeIgniter)
上面的指令会导致 500 错误,所以我想可能是因为 1.3 和 2.x 之间可能存在一些语法差异。
经过一些尝试和错误编辑后,我发现重写规则本身有问题,但我真的不明白为什么。
- 关于为什么我的重写规则不起作用有什么想法吗?以前在很多不同的服务器上都是这样做的。
- 建议如何解决?
注意:mod_rewrite 确实有效,我已经编写了一个小测试来确定。
I'm using a couple of rewrite directives that always works before on apache2 but now trying a new shared hosting and the rewrite rules do not seem to get applied.
I've reduced the .htaccess files to the following essential rules:
RewriteEngine On
Rewritebase /demo/
RewriteRule ^(.*)$ index.php/$1 [L]
As you can see, i want to rewrite every request to my index.php file in the demo folder from root.
So everything like http://www.example.com/demo/albums/show/1 should be processed by http://www.example.com/demo/index.php for a standard MVC setup. (I'm using CodeIgniter btw)
The directives above results in a 500 error, so i thought maybe because of some possible syntax differences between 1.3 and 2.x.
After some trail and error editing, i've found the rewrite rule itself to be at fault but i really don't understand why.
- Any ideas to why my rewrite rule doesn't work? it did before on lots of different servers.
- Suggestions how to fix it?
Note: mod_rewrite does work, i've written a small test to be sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在你的位置,我可能会首先查看 Apache 错误日志,然后尝试通过执行以下操作来消除一个移动部分:
如果有效,我会尝试重新引入 RewriteBase。
In your position, I'd probably look in the Apache error log first, then would try to eliminate one moving part by doing
If that worked, I'd try reintroducing RewriteBase.
设置:
您是否在重写规则之前 ...?如果
FollowSymLinks
被禁用,mod_rewrite 将不起作用。Did you set:
… before the rewrite rules? If
FollowSymLinks
is disabled mod_rewrite won’t work.您可能会遇到无限递归,因为
index.php/...
也与^(.*)$
匹配。所以尝试排除你的目标:It may be that you’re running into an infinite recursion since
index.php/…
is also matched by^(.*)$
. So try to exclude your target: