2010-11-03 33 views
1

我目前正在開發一個項目,其中我的Apache documentroot與我的index.php所在的公共目錄不同。奇怪的是,由於這個設置,我的$ _GET超全球似乎被清空了。

目錄結構:

  • /DocumentRoot的
  • /Documentroot/.htaccess
    • /public/.htaccess
    • /public/index.php

處理第一個.htaccess後出現問題。

#First .htaccess in Apache documentroot: 
RewriteEngine On 
RewriteRule (.+) public/$1 [NC,L] 

# Second .htaccess in /documentroot/public: 
SetEnv APPLICATION_ENV testing 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

一些觀察:

  • 當刪除主的.htaccess,並把額外的index.php在documentoot,我的$ _ GET變量顯示細膩
  • 當傾倒$ _GET /public/index.php文件,它是空的
  • 當調用index.php像/?foo = bar時,$ _GET爲空
  • 當調用index.php像/ ind ex.php?富=酒吧$ _GET填充

什麼引起$ _GET變量被掏空?任何幫助表示讚賞。

編輯:事情只是得到了一大堆陌生人:

當我離開這兩個.htaccess文件完好,並放置一個index.php文件(無論(或任何指數*爲此事)。什麼內容),/ public目錄中的index.php文件被解析,$ _GET變量被正確填充。

+0

可能不是問題,但是您確定在文檔根目錄中沒有「index.htm」或其他類似文件嗎?嘗試將'DirectoryIndex index.php'添加到'.htaccess'中。 – 2010-11-03 16:25:55

+0

感謝您的評論,但我確定這不是問題。 – 2010-11-03 17:18:46

回答

0

我在這裏猜測,但是當請求/?foo=bar時,正則表達式(。+)可能試圖匹配空字符串,從而導致測試失敗。嘗試將其更改爲(。*)。

編輯:其實,經過再三考慮,要求/?foo=bar的時候,如果它匹配「/」,然後將其重寫爲public//,這將是你的最後一條規則得到改寫爲index.php。也許試試^/?(.*)$作爲你的第一個模式。

+0

感謝您的評論,但可悲的是,這並沒有奏效。 – 2010-11-03 17:19:25

0

這裏發生的事情:

  1. 您要求/?foo=bar
  2. documentroot/.htaccessRewriteRule重定向到public/?foo=bar
  3. public/.htaccess中,RewriteCond支票是否是一個文件,一個符號,或目錄。字符串/?foo=bar不屬於這些,因此跳過了第一個RewriteRule
  4. RewriteRule ^.*$ index.php [NC, L]運行。這指示所有index.php - 這是一個沒有任何$ _GET變量的URL。這就是爲什麼他們正在消失。

您需要在最後的RewriteRule中傳遞那些GET變量。

+0

我已經嘗試將QSA標誌添加到rewriterule中,但這不起作用。這不是問題。 – 2010-11-10 07:31:46