Apache 相当于 lighttpd url.rewriteonce?

发布于 2024-07-18 05:14:57 字数 973 浏览 3 评论 0原文

我的应用程序入口点是这样的。

/app/index.php <-- this is the main dispatcher.

/app/ 下的应用程序特定文件夹

/app/todo/
/app/calendar/
/app/bugtrack/

每个应用程序文件夹都包含应用程序特定文件。

我想通过应用程序下的所有请求来传递/app/index.php。

以便。

/app/todo/list/today -> goes to /app/index.php
/app/ -> goes to /app/index.php
/app/bugtrack/anything/else goes to /app/index.php

在我的 lighttpd 测试机上,我可以通过编写这样的规则轻松做到这一点。

url.rewrite-once = (
    "^\/app\/todo\/*"   => "/app/index.php",
    "^\/app\/calendar\/*"   => "/app/index.php",
    "^\/app\/bugtrack\/*"   => "/app/index.php",
)

现在需要使用 .htaccess 和 mod_rewrite 使其在 Apache 上运行。

但无论我做什么,都不起作用。

我在 /app/.htaccess 中编写了以下内容,

RewriteEngine on
RewriteRule .* index.php [QSA]

它适用于 /app/ 和 /app/todo/ 但不适用于 /app/todo/list/today 。

任何人都可以告诉我该怎么做吗?

I have my application entry point like this.

/app/index.php <-- this is the main dispatcher.

And application specific folders under /app/

/app/todo/
/app/calendar/
/app/bugtrack/

Each application folder cotains application specific files.

I would like to pass all requests unders app to pass through /app/index.php.

So that.

/app/todo/list/today -> goes to /app/index.php
/app/ -> goes to /app/index.php
/app/bugtrack/anything/else goes to /app/index.php

On my lighttpd test machine I can easily do it it by writing a rule like this.

url.rewrite-once = (
    "^\/app\/todo\/*"   => "/app/index.php",
    "^\/app\/calendar\/*"   => "/app/index.php",
    "^\/app\/bugtrack\/*"   => "/app/index.php",
)

Now need to make it work on Apache using .htaccess and mod_rewrite.

But no matter what I do, it's not working.

I wrote the following in /app/.htaccess

RewriteEngine on
RewriteRule .* index.php [QSA]

It works for /app/ and /app/todo/ but fails for /app/todo/list/today for example.

Anyone can give me any idea how to do it?

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

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

发布评论

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

评论(1

乖乖兔^ω^ 2024-07-25 05:14:57
RewriteEngine On
RewriteBase /app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

这样做的作用是,如果请求不是文件名或目录,则将其重写为index.php。 然后检查$_SERVER[REQUEST_URI]

RewriteEngine On
RewriteBase /app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

What this does is if the request is not a filename or a directory, rewrite it to index.php. Then check $_SERVER[REQUEST_URI].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文