重写规则在 apache 1.3 中不起作用

发布于 2024-08-31 15:44:51 字数 781 浏览 1 评论 0原文

我正在使用一些以前在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿忘初心 2024-09-07 15:44:51

在你的位置,我可能会首先查看 Apache 错误日志,然后尝试通过执行以下操作来消除一个移动部分:

RewriteEngine On
RewriteRule ^/demo/index.php$ /demo/index.php [L]
RewriteRule ^/demo/(.*)$ /demo/index.php/$1 [L]

如果有效,我会尝试重新引入 RewriteBase。

In your position, I'd probably look in the Apache error log first, then would try to eliminate one moving part by doing

RewriteEngine On
RewriteRule ^/demo/index.php$ /demo/index.php [L]
RewriteRule ^/demo/(.*)$ /demo/index.php/$1 [L]

If that worked, I'd try reintroducing RewriteBase.

千里故人稀 2024-09-07 15:44:51

设置:

Options +FollowSymLinks

您是否在重写规则之前 ...?如果 FollowSymLinks 被禁用,mod_rewrite 将不起作用。

Did you set:

Options +FollowSymLinks

… before the rewrite rules? If FollowSymLinks is disabled mod_rewrite won’t work.

不回头走下去 2024-09-07 15:44:51

您可能会遇到无限递归,因为 index.php/... 也与 ^(.*)$ 匹配。所以尝试排除你的目标:

RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]

It may be that you’re running into an infinite recursion since index.php/… is also matched by ^(.*)$. So try to exclude your target:

RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文