1

私は奇妙な問題を抱えています。ローカルマシンでは完全に機能するCodeigniterアプリケーションがありますが、リモートサーバーでは機能しません。以下はシナリオです

  1. 末尾にスラッシュがあるリンクは機能しますが、末尾にスラッシュがない場合は、Firefoxで「接続がリセットされました」というエラーが表示されます。

  2. 末尾のスラッシュがないリンクは機能しますが、末尾のスラッシュがあると、Firefoxで「接続がリセットされました」というエラーが表示されます。

なぜなら、コーディングにエラーはないと確信しています。犯人は.htaccessファイルだと思います。以下は私の.htaccessファイルです

RewriteEngine on
RewriteBase /demo/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

どんな助けでも大歓迎です。ありがとう!

4

1 に答える 1

6

あなたの問題は「?」が欠けていると思います。この行で:

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

これを追加 '?' 「index.php」の直後

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

また、私の経験では、RewriteBase の末尾のスラッシュを省略して $config['base_url'] パラメータに追加し、代わりに CI にその作業を任せます。

$config['base_url'] = 'http://yourwebsite.com/demo/';
-instead of-
$config['base_url'] = 'http://yourwebsite.com/demo';

これは、CI でしばらく使用した .htaccess セットアップであり、うまく機能しています。

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase / # TODO: add a folder name here if the application is not in web root

  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]
</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> 
于 2013-01-09T17:38:51.617 に答える