2011-07-20 8 views
5

URLから「index.php」を削除するcodeigniterアプリケーションにhtaccessファイルを追加しました。 URLはうまくいきましたが、参照が絶対的であってもCSSリンクは機能しません(つまり、 "http:// ...")画像やその他のリンクはすべて正常に動作しますが、負荷はありません。これはHTAccessファイルです。CodeIgniter HTAccessはCSSファイルをロードしません

RewriteEngine on RewriteCond $1 !^(main.php|images|robots.txt) RewriteRule ^(.*)$ main.php/$1 [L]

と私は同じCIのインストールに2つの異なるアプリケーションを使用するので、はい今の私のインデックスファイルはmain.phpです。助けてくれてありがとう。

答えて

9

また、次を試してみてください:

# 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 ^(.*)$ main.php/$1 [L] 

これはあなたがすることなく、あなたがウェブルート(スタイル、イメージ、スクリプト)で好きなフォルダを作成できるようになりますそれらをhtaccessファイルで宣言します。

+0

robots.txtとサイトマップを忘れないでください。 –

+0

これはこのコードとは無関係です。ファイルがファイルシステム内で有効かどうかを確認し、存在しない場合はアプリケーションのmain.phpファイルにリダイレクトします。これはrobots.txt、sitemapsのためにうまくいくでしょう - ほとんど何でも。 – simnom

+0

申し訳ありませんが気にしませんでした。火格子ソリューション。 –

2

あなたのhtaccessファイルは、1行:)

RewriteEngine on 
RewriteCond $1 !^(main\.php|images|robots\.txt|styles) 
RewriteRule ^(.*)$ /main.php/$1 [L] 

は、あなたがするRewriteCondラインで、あなたのスタイルのディレクトリを置くことができますが不足しています。例えばスタイルを追加しました。

詳細情報here

+0

を示すような画像がさらにBASE_URL機能を使用ここにアクセスしたいURLを追加する必要があります。さもなければ、main.php/$ urlページにリダイレクトされます(それは当然、存在しません)。 –

1

私が今使っている.htaccessファイルを見てみたいです。

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt|css|design|img|js) 
RewriteRule ^(.*)$ /a-cat/index.php/$1 [L] 
</IfModule> 

ディレクトリ構造はこのようなものです:

enter image description here

CSSファイルは、このように使用することができます:私はこれを使用

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/main.css" /> 
2

。よくコメントされていて、明らかに私によって書かれていません。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    #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> 
0

この問題に対する簡単な答えは:あなたのCSSのパスの下と上で与えられたとして、CodeIgniterのからの.htaccessのコードを使用してJSと

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase # The path to your project/official/hrm/ 

    #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> 

<link rel="stylesheet" href="<?php echo base_url(); ?>the rest of path to yourfile"> 
関連する問題