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

仅当文件存在时重写,它是GET请求。

  •  0
  • Knerd  · 技术社区  · 8 年前

    我正在开发一个PHP CMS,目前正在实现一个静态文件缓存。缓存背后的想法是,所有页面都编译成html,然后由apache或nginx提供服务。问题是,如果它不是GET请求,那么它仍然应该被重写到PHP CMS,而不是直接服务。这是我当前的htaccess配置,我取消了HTTPS重定向。

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # If the requested filename exists, simply serve it, but only if it is a GET request
        # We only want to let Apache serve files and not directories.
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteCond %{REQUEST_METHOD} =GET
        RewriteRule ^ - [L]
    
        # Rewrite all other queries to the front controller.
        RewriteRule ^ %{ENV:BASE}/index.php [L]
    </IfModule>
    

    但只要我发送一个POST请求,它就会失败,并出现错误500。apache错误日志显示以下消息:

    AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://jinya.local/contact
    AH00121: r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /index.php, referer: http://jinya.local/contact
    AH00122: redirected from r->uri = /contact, referer: http://jinya.local/contact
    

    有人能帮我弄清楚是什么问题吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Justin Iurman    8 年前

    最后一条规则创建一个无限重写循环。

    解决方法:不要对基索引应用规则

    RewriteCond %{REQUEST_URI} !/index\.php$ [NC]
    RewriteRule ^ %{ENV:BASE}/index.php [L]