0

それを達成した後、私は(ホスティング会社のgodaddyのために)index.php?自分のウェブサイトのURLから削除するのに苦労しました. その後、何人かの ユーザー
が私のウェブサイトに古いURL ( . インターネットを少し検索しましたが、問題の背後にある理由は、同じページ要求に含まれているが 含まれていない(推奨)すべてのURL からリダイレクトする必要があるためだと思います。index.php?/
index.php?


index.php?/example.comindex.php?/

例: リクエストするとorexample.com/index.php?/site/category/etcにつながります (推奨される方法)。 他の URL も同じように扱われます。example.comexample.com/site/category/etc

これが私の現在の.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 ソリューションを試す:(Robin 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'
);

結局、結果が出ませんでした。

4

1 に答える 1

1
$CI =& get_instance();

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

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

これをフックまたは自動ロードされたヘルパーに追加すると、それが実行されます。

于 2012-05-31T08:35:21.580 に答える