2014-09-29 97 views
0

我有一個使用CodeIgniter創建的網站,儘管URL重寫正在我的本地安裝(WAMP)上工作,但它在遠程服務器上失敗。CodeIgniter:URL重寫不起作用

CI框架安裝在「/ dev」文件夾中。

這裏的錯誤,當我嘗試使用以下URL訪問控制:http://www.mywebsite.com/dev/controller

未找到

請求的URL /dev/index.php/controller/此服務器上未找到。

我試過每個.htaccess和config.php的組合,但我找不出什麼是錯的。

但是,http://www.mywebsite.com/dev/工作得很好。

這裏的.htaccess文件:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 

和應用程序/配置/ config.php文件:

$config['base_url']  = '/dev/'; # I tried to put the whole path, didn't work either 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'QUERY_STRING'; # I tried every possibility, none of them work 
$config['url_suffix'] = ''; 

什麼是真正奇怪的是,這種精確的配置中使用到另一臺服務器上運行,我今天移動了我的代碼,現在它不工作...

任何想法?

回答

1

您在重寫規則中未使用查詢字符串,您正在使用路徑信息。嘗試改變的URI協議:

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

如果仍然不行,請嘗試更改您的規則,追加查詢字符串,而不是:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php?$0 [PT,L] 
#      ^------ a "?" here instead of "/" 

,並確保htaccess文件是在dev目錄。

+0

設置URI協議PATH_INFO沒有工作,但是你的第二個解決方案被證明是有效的。 功能答案在不到5分鐘內,上帝我愛Stackoverflow。謝謝 ! – roberto06 2014-09-29 14:47:01

0

嘗試

RewriteEngine On 
RewriteBase /your_project_name/ 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

和賓果