【问题标题】:Apache equivalent of lighttpd url.rewriteonce?Apache 相当于 lighttpd url.rewriteonce?
【发布时间】:2009-04-22 18:36:40
【问题描述】:

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

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

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

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

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

我想通过/app/index.php传递app下的所有请求。

这样。

/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 无效。

谁能告诉我怎么做?

【问题讨论】:

    标签: apache mod-rewrite lighttpd


    【解决方案1】:
    RewriteEngine On
    RewriteBase /app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    如果请求不是文件名或目录,则将其重写为 index.php。然后查看$_SERVER[REQUEST_URI]

    【讨论】:

    • 一个问题是 /app/todo/ 是一个目录。但在这种情况下,我也需要强制向 /app/index.php 发出请求。第二个 /index.php 似乎将请求重定向到根目录(主页)的 index.php 而不是 /app/index.php。我正在尝试解决这些问题并检查发生了什么
    • 嗯,如果您想重定向存在的目录,请尝试删除以 !-d 结尾的行,然后在最后一行尝试 index.php 或 /app/index.php。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 2010-09-23
    • 2019-01-21
    相关资源
    最近更新 更多