【问题标题】:.htaccess rule seemingly ignored.htaccess 规则似乎被忽略了
【发布时间】:2014-11-15 13:44:20
【问题描述】:

我有一个管理路由的 Marionette 应用程序,但我不希望它为对 server.com/api/anything/at/all 的 api 调用请求处理它们

我的规则现在看起来像这样,但 Marionette 似乎总是能抓住它,即使是 /api/*

# ------------------------------------------------------------------------------
# | Marionette                                                                    |
# | If it's not for /api/*, then handle it                                        |
# ------------------------------------------------------------------------------

<ifModule mod_rewrite.c>
    DirectorySlash Off
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteCond %{REQUEST_URI} !^/api/ [NC]
    RewriteRule ^(.*)index.php $1 [R,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/index\.php
    RewriteRule (.*) index.php
</ifModule>
# ------------------------------------------------------------------------------
# | Phalcon                                                                    |
# | If it fell through, handle with Phalcon                                    |
# ------------------------------------------------------------------------------

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

谁能告诉我我在这里做错了什么吗?谢谢。

编辑:如果它给出任何清晰,上面的 .htaccess 在我的 /public 文件夹中。在我的根文件夹中:

# ------------------------------------------------------------------------------
# | Phalcon                                                                    |
# ------------------------------------------------------------------------------

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

公共重写工作正常。我只是想我会分享它,以防它在公共场合影响到我没有想到的那个。谢谢!

【问题讨论】:

    标签: apache .htaccess mod-rewrite marionette phalcon


    【解决方案1】:

    Marionette的规则应该是这样的:

    <ifModule mod_rewrite.c>
        DirectorySlash Off
        RewriteEngine On
        RewriteCond %{THE_REQUEST} ^.*/index.php
        RewriteCond %{REQUEST_URI} !^/api/ [NC]
        RewriteRule ^(.*)index.php $1 [R,L]
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{THE_REQUEST} !\s/+(index\.php|api/) [NC]
        RewriteRule ^ index.php [L]
    </ifModule>
    

    【讨论】:

    • 我用你的替换了我的块,我仍然得到相同的响应。 server.com/ -- Marionette server.com/api/ -- Marionette server.com/api/test -- Marionette
    • 是的,这行得通 - 谢谢。关于如何确保它仅适用于 server.com/api/x/y/z 的任何想法?我用 server.com/marionette/api/ 进行了测试,因为它包含“api”,所以它通过 phalcon 的规则感觉。所以我想让规则说 /api/ 在开头?
    • 我进一步调整了规则以匹配 /api/ 仅在开始时。
    猜你喜欢
    • 2023-03-25
    • 2021-10-28
    • 2016-09-30
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2012-03-08
    • 2015-12-11
    相关资源
    最近更新 更多