RewriteRule 500错误问题

发布于 2024-11-02 10:58:18 字数 507 浏览 0 评论 0原文

我设置了以下重写规则:

RewriteEngine On

RewriteRule ^api/([A-Za-z0-9-]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)$ index.php/other/$1 [NC,L]

不幸的是,这些规则导致我的服务器抛出 500 错误。单独来看,它们都工作得很好。

我的意图是,如果请求是 http://somesite.com/api/whatever/,第一条规则将被触发,重定向到 index.php/api/whatever/ code>

如果除“api”之外的任何内容作为第二段发送,它将重定向到 index.php/other/whatever

我的理解有什么缺陷吗?我认为它会出现在列表中,并且带有 L 标志,一旦遇到某些东西就会停止执行。或者我的语法错误?

干杯

I have the following Rewrite Rules set up:

RewriteEngine On

RewriteRule ^api/([A-Za-z0-9-]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)$ index.php/other/$1 [NC,L]

Unfortunately these cause my server to throw a 500 error. Taken individually, they both work fine though.

My intention is that if the request is http://somesite.com/api/whatever/, the first rule will get triggered, redirecting to index.php/api/whatever/

If anything other than "api" gets sent as the second segment though, it will redirect to index.php/other/whatever.

Is my understanding flawed somehow? I thought that it would go down the list, and with the L flag, would stop executing once it hit something. Or is my syntax wrong?

Cheers

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

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

发布评论

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

评论(2

时光沙漏 2024-11-09 10:58:18
  1. 每当您收到 500 时,请检查 /var/log/httpd/error_log (或系统上的等效路径)。
  2. 我很确定字符组中的连字符是正则表达式语法错误。 (另外,[NC]标志使[A-Za-z]变得多余

尝试:

RewriteRule ^api/([-A-Z0-9]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([-A-Z0-9]+)$ index.php/other/$1 [NC,L]

或者也许

RewriteRule ^api/([^/]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([^/]+)$ index.php/other/$1 [NC,L]
  1. whenever you get a 500, check /var/log/httpd/error_log (or the equivalent path on your system.)
  2. I'm pretty sure the hyphen char in your character group is a regex syntax error. (also, the [NC] flag makes [A-Za-z] redundant

Try:

RewriteRule ^api/([-A-Z0-9]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([-A-Z0-9]+)$ index.php/other/$1 [NC,L]

Or perhaps

RewriteRule ^api/([^/]+)$ index.php/api/$1 [NC,L]
RewriteRule ^([^/]+)$ index.php/other/$1 [NC,L]
恰似旧人归 2024-11-09 10:58:18

我认为您需要 QSA 标志 ,尝试这样:

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

I think you need QSA flag, try like that :

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