0

私はCodeIgniterベースのアプリケーションに取り組んでいます。私のhtacessは次のようになります:

RewriteEngine On
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^(.*)$ /index.php?$1 [L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

これはほとんどの部分でうまく機能し、次のようなコントローラーとメソッドにアクセスできます。

http://example.com/controller/method/args

ただし、このようにwwwが付加されている場合

http://www.example.com/foo

にリダイレクトします

http://example.com/index.php?foo

表示されるページは常に私のサイトのインデックスページです。

RewriteCond / RewriteRuleの最後のペアを追加してwww、存在する場合は単に削除しました。

どうやってそれを思い通りに動かすのかよくわからないので、

http://www.example.com/foo

にリダイレクトするだけです

http://example.com/foo

編集

私のCI構成ファイルから:

$config['base_url'] = 'http://example.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
4

2 に答える 2

3

コメントで述べたように。

書き換えルールRewriteRule ^(.*)$ /index.php?$1 [L]は一番下に配置する必要があります。[L]この場合、あなたの旗のために注文が重要になります。

于 2012-07-05T20:33:02.553 に答える
1

ここではStevenLu以上のものを提供していません...しかし、もう少し意味をなすように注文をクリーンアップしました

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteCond  %{REQUEST_FILENAME} !-f
# You don't really need the !-d (directory) flag here
RewriteRule ^(.*)$ /index.php [L] # Could put QSA in here too, but CI doesn't play too nice with query strings 
于 2012-07-05T20:39:03.657 に答える