代码之家  ›  专栏  ›  技术社区  ›  CDR

Apache相当于lighttpd url.rewriteonce?

  •  1
  • CDR  · 技术社区  · 16 年前

    我有这样的申请入口点。

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

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

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

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

    我想通过app下面的所有请求来通过/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重写的Apache上工作。

    但不管我做什么,它都不起作用。

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

    RewriteEngine on
    RewriteRule .* index.php [QSA]
    

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

    有人能告诉我怎么做吗?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Mariano    16 年前
    RewriteEngine On
    RewriteBase /app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

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