错误 500 或重写规则以获取干净的 URL

发布于 2025-01-04 20:27:52 字数 325 浏览 2 评论 0原文

.htaccess 中使用以下重写规则时,我不断收到 500 内部服务器错误:

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

本质上,我希望 Web 应用程序上有干净的 URL,即 www.example.com/login 的功能与 www.example.com/index.php/login 相同。

此重写规则在 MAMP 本地和不同的 Apache 测试服务器上运行良好,但在客户端基于 1and1.com 的托管上失败。

I keep getting a 500 Internal Server Error when using the following Rewrite rule in my .htaccess:

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Essentially, I want clean urls on my web application, i.e. www.example.com/login would function the same as www.example.com/index.php/login.

This rewrite rule works fine locally on MAMP and on a different Apache test server, but fails on the client's 1and1.com-based hosting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

阪姬 2025-01-11 20:27:52
RewriteRule ^(?!index\.php).*$ index.php/$0 [L,QSA]

您需要防止无限循环。对 index.php 的否定断言是阻止这种情况的一种方法。

RewriteRule ^(?!index\.php).*$ index.php/$0 [L,QSA]

You need to prevent the infinite loop. A negative assertion on index.php is one way to stop this.

东走西顾 2025-01-11 20:27:52

实际上,我在 CodeIgniter 论坛 中找到了答案。

它并没有修复我的规则,而是采用了稍微不同的方式:

Options -MultiViews
RewriteEngine on
RewriteBase /dev
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php/$1 [L] 

I actually found the answer over at the CodeIgniter forum.

It didn't fix my rule, but instead went at it a slightly different way:

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