【问题标题】:$_GET array is empty$_GET 数组为空
【发布时间】:2011-06-25 10:57:23
【问题描述】:

我的 Kohana 3 应用程序使用了相当多的 $_GET 参数。但是,当我部署应用程序时,我得到了一个空白页,其中只有文本“未指定输入文件”。通过更改我的 .htaccess 文件,我很快找到了解决这个看似常见问题的方法:

RewriteRule .* index.php/$0 [PT,L]

RewriteRule .* index.php?$0 [PT,L]

但是现在我的 $_GET 数组丢失了所有传递的参数。任何不需要 $_GET 的页面都可以正常工作。我不太擅长 .htaccess 文件,但据我所知,添加 ?已将 $_GET 数组替换为 uri。

我也试过

RewriteRule .* index.php/?$0 [PT,L]

RewriteRule .* index.php?/$0 [PT,L]

但无济于事。

以下是我的完整 .htaccess 文件(与 example.htaccess 大体相同)

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?$0 [PT,L]

我找到的最接近解决方案的是这篇文章: http://forum.kohanaframework.org/discussion/comment/4857/#Comment_4857 然而,这似乎是针对较旧版本的 Kohana,我不确定这在 Kohana v3 中如何工作。

【问题讨论】:

    标签: php apache .htaccess kohana kohana-3


    【解决方案1】:

    使用QSA(查询字符串追加)应该会有所帮助:

    RewriteRule .* index.php?$0 [PT,L, QSA]
    

    【讨论】:

    • 完美,如此简单。你让我今天很开心。谢谢。
    【解决方案2】:

    我必须对 K03 example.htaccess 进行两项更改才能使其正常工作:

    RewriteRule ^(application|modules|system)/ - [F,L] 而不是

    RewriteRule ^(?:application|modules|system)\b - [F,L](这会导致内部服务器错误)

    RewriteRule .* index.php [L] 而不是

    RewriteRule .* index.php/$0 [PT](给出没有指定输入文件的消息。)

    这是我的 K03 的 .htaccess 文件:

    # Turn on URL rewriting
    RewriteEngine On
    
    # Installation directory
    #RewriteBase /
    
    # Protect hidden files from being viewed
    
        Order Deny,Allow
        Deny From All
    
    # Protect application and system files from being viewed
    RewriteRule ^(application|modules|system)/ - [F,L]
    
    # Allow any files or directories that exist to be displayed directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Rewrite all other URLs to index.php/URL
    RewriteRule .* index.php [L]
    

    【讨论】:

    • 奇怪的是,当我将最后一行更改为 RewriteRule .* index.php [L] 时,此解决方案也有效
    • @jord - 这是我摆脱 500 错误的唯一方法 - 谢谢!
    【解决方案3】:

    得到了完全相同的错误,我认为这是由于我的 apache 在 fastcgi 模式下工作造成的。 上述任何带有 htaccess 规则的解决方案都对我有用,但在网上搜索我发现了这个规则:

    RewriteRule .* index.php?kohana_uri=$0 [PT,L,QSA]

    然后用它替换旧的: RewriteRule .* index.php/$0 [PT,L]

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 1970-01-01
      • 2020-06-14
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 2020-02-21
      • 2015-07-06
      相关资源
      最近更新 更多