2012-05-31 16 views
0

我掙扎着(因託管公司,godaddy)從我網站的網址中刪除index.php?,之後完成這一點。
後,我注意到一些用戶使用的是舊的URL(具有index.php?/
所以,我嘗試使用重定向重定向用戶index.php?的網頁來了,但沒有運氣訪問我的網站。
我在網上搜索了一點點,
但我認爲這個問題背後的原因是,我需要它從所有網址
包括index.php?/example.com或同一頁面的請求,但沒有index.php?/重定向(首選)。Codeigniter:清理我的網址(刪除index.php)後,我無法將訪問我網站的用戶重定向到新的整潔網址

例如:請求example.com/index.php?/site/category/etc將導致example.comexample.com/site/category/etc(首選方法)。
其他任何URL都將被視爲相同。

這是我目前的.htaccess文件(沒有與此相關的問題):

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

更新
試圖PHP的解決方案:(學分羅賓Castlin)
我試圖用鉤(基於在答案),但沒有工作! 我啓用hooks從配置和URL助手是自動加載。
這個功能裏面application/hooks/MY_hooks.php

function redirectToNewURL(){ 

    if(preg_match('~/index.php?/~', $_SERVER['REQUEST_URI'])) {//check if the URL has index.php 
     header('Location: '.current_url(), true, 301); //redirect 
     exit; 
    } 
} 

這我如何設置掛鉤:
application/config/hooks.php
我把這個簡單的數組:

$hook['pre_controller'] = array(
    'class' => '', 
    'function' => 'redirectToNewURL', 
    'filename' => 'MY_hooks.php', 
    'filepath' => 'hooks' 
); 

最終,我沒有得到結果。

回答

1
$CI =& get_instance(); 

$CI->load->helper('url'); 

if (preg_match("~/index\.php\?/~", $_SERVER['REQUEST_URI'])) { 
    header('Location: '.current_url()); 
    exit; 
} 

將此添加到鉤子或自動加載的助手應該這樣做。

+0

我更新我的答案,請檢查它 – Abdulaziz

+0

你不需要上課嗎?或者該功能是否被執行? –

+0

from codeigniter's manual:'class您希望調用的類的名稱。如果您更喜歡使用程序功能而不是班級,請將此項留空.' – Abdulaziz

相關問題