0

CodeIgniter アプリケーションを作成しましたが、mod_rewrite を使用して URL をクリーンアップしたいと考えています。CodeIgniter アプリケーションを htdocs/ci-intro/ にインストールしました

ここに私の .htaccess ファイルがあります:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
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> 

CodeIgniter の config.php を次のように変更しました。

$config['base_url'] = '';
$config['index_page'] = '';

リンクを使用して about ページに移動するたびに、CodeIgniter から 404 メッセージが表示されます。ただし、ブラウザの URL は「クリーンアップ」されているようです (index.php は削除されています)。これは URL です:

「http://localhost:8888/ci_intro/about」

404エラーを取り除き、実際に使用をaboutページに誘導するのを手伝ってくれる人はいますか?

OS: MAC OS X 10.8.2 (最新)
サーバー ソフトウェア: MAMP
PHP: 5.2.17
ブラウザー: Chrome & Safari (両方のブラウザーでこの問題が発生します)

4

4 に答える 4

1

サーバー構成を確認する前に、以下のコードを試してください。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]


#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
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-08T13:02:11.863 に答える
1

これを試して...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Your_folder_Name/index.php?/$1 [L]
</IfModule>
于 2013-01-28T06:53:45.337 に答える
0
RewriteCond %{REQUEST_URI} ^system.*

REQUEST_URI が / で始まるため、おそらくトリガーされません。試す

RewriteCond %{REQUEST_URI} ^/system

同上

RewriteCond %{REQUEST_URI} ^application.*

そして、あなたのシステムは本当に /index.php?/blah blah を必要としていますか? ? の後に URL クエリ文字列が必要です。

于 2013-05-31T14:02:01.730 に答える