2011-12-02 35 views
0

我在我的.htaccess以下規則:的Apache的環境變量沒有mod_rewrite的規則設定

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php$ 
    RewriteRule ^(.*)$ index.php?q=$1 [L] 
</IfModule> 

此查詢字符串值q設置爲請求URI(就是那個索引之前剝離前述任一目錄.php駐留在)。例如:http://localhost/framework/testingq=testing

我想改變這個,以便設置一個查詢字符串,而不是設置一個環境變量。我曾嘗試以下,但它不工作(環境VAR不被設置):

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php$ 
    RewriteRule ^(.*)$ index.php [ENV=request:$1,L] 
</IfModule> 

奇怪的是,環境VAR將設置如果請求與index.php文件開始,例如:http://localhost/framework/index.php/testingq=index.php/testing

回答

2

使用PATH_INFO(按照@chrono的建議)和稍微不同的mod_rewrite規則我已經得到了所需的東西!

修改的.htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 
+0

你可以檢查你的答案現在有效;) –

+0

我想;它回答了我問的問題,但它不適用於別名的URL(共享ssl)。我的目標是不必在我的PHP中指定一個基本的URL。 –

+0

這麼好,錯......修改你的問題,或檢查這個有效,也許問另一個? –

0

我想,你實際上尋找的是PATH_INFO - 如下所述:What exactly is PATH_INFO in PHP?

無需推倒重來,除非有一些其他的原因。

+0

這個作品就像目前的情況;只有當url以index.php開頭時纔會被設置。我試圖讓apache env var被設置爲任何請求。 –

+0

我現在已經開始使用您提供的建議了,謝謝! downvote道歉,我竊聽了我手機上的錯誤箭頭,直到現在才注意到。 –