2009-12-09 35 views
1

我需要從AUTO更改$config['uri_protocol']到PATH_INFO(允許使用網址參數)

我的問題:當我設置$config['uri_protocol']="PATH_INFO";正規網址,停止工作,我得到的主頁沒有關於我點擊了哪個網站頁面的URL。

print_r($ _SERVER)顯示我添加的url參數只出現在REQUEST_URI中,而不出現在其他$ _SERVER部分中。

我的htaccess是standard one

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # This is different between local host and production server!!! 
    RewriteBase/


    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

UPDATE:

我改變

RewriteRule ^(.*)$ index.php?/$1 [L] 

RewriteRule ^(.*)$ index.php?/$1 [QSA,L]允許網址參數來傳遞。現在,網址參數也出現在

$_SERVER 

REDIRECT_QUERY_STRING, QUERY_STRING AND REQUEST_URI 

問題:我嘗試了所有上述選項的$ config ['uri_protocol'],但仍然無論何時添加URL參數,CI都會給出錯誤404。

注意:我在2臺服務器上嘗試了上述操作。其中一個是centos5/Apache2/Plesk VPS,另一個則是在xampp/Vista上。

回答

0
+0

嘿,我剛剛通過Google發現了這個問題。我有和你在這裏描述的完全一樣的問題。我需要使用URL查詢字符串,但如果我將$ config ['uri_protocol']更改爲「PATH_INFO」(這是允許查詢字符串工作所需的),則我的所有頁面都會簡單地重定向到主頁。 現在我跟着你在這裏提供的鏈接,但我不明白你的解決方案(它似乎不適用於我)。我可以問你爲什麼設置了$ config ['uri_protocol'],你的.htaccess現在是什麼樣的? 非常感謝。 :) – 2010-06-24 17:37:20

+0

對不起,我想出了一個解決方案(hack hack hack:P)。我的主機(出於某種原因)不允許PATH_INFO變量。所以我只是將ORIG_PATH_INFO值複製到PATH_INFO變量中。 Et瞧! – 2010-06-24 18:08:36

+0

$ _SERVER ['PATH_INFO'] = $ _SERVER ['ORIG_PATH_INFO'];作品不錯 – 2013-04-05 15:03:26

1

您應該在mod_rewrite的最後一條規則中使用[QSA]選項... 這會將查詢字符串參數(我的意思是在'?'之後)附加到最終的URL。

你的統治就結束這樣的:

RewriteRule ^(.*)$ index.php?baseurl=$1 [QSA,L] 

如果您的請求是:

http://yourhost.com/module/action?param1=value1&param2=value2 

最後,你會得到:

http://yourhost.com/index.php?baseurl=/module/action&param1=value1&param2=value2 

我沒有測試它。這是你真正想要的嗎?

+0

嗨Arno, 感謝您的提示。它沒有完全解決問題,請參閱原始問題中的更新。 – Nir 2009-12-09 17:33:20

+0

您是否嘗試刪除「?」之間的尾部斜線和「$ 1」? – Arno 2009-12-09 19:17:33

1

在這種情況下,你不希望設置$配置[ 'uri_protocol']到PATH_INFO。 var_dump($ _ SERVER)在某處並根據需要查找哪個變量包含您的路徑,然後將其設置爲該值(如果AUTO不起作用)。

3

我有同樣的問題,當我設置uri_protocol PATH_INFO然後我的網站的所有鏈接去默認控制器&行動。後來我發現,我的服務器不支持PATH_INO變量,所以我沒有在config.php兩個步驟來解決問題:

第一:

$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; 

然後:

$config['uri_protocol'] = 'PATH_INFO'; 

上述兩線解決了我的問題。

+0

謝謝,這節省了我很多時間! – 2011-08-26 18:10:00

+0

謝謝,這是工作。這是Cpanel的錯! – 2013-04-05 15:02:30

1

最好的方法是檢查你從服務器獲得哪個參數。

如果您獲得$_SERVER['PATH_INFO'],請使用以下內容。

$config['uri_protocol'] = 'PATH_INFO'; 

否則,如果你得到$_SERVER['ORIG_PATH_INFO'],使用此:

$config['uri_protocol'] = 'ORIG_PATH_INFO'; 

,讓您的配置文件,這些改變。