2017-08-21 6 views
1

私たちは何年もの間、次のファイルを使用しています:.htaccess我々はApache 2.4.7を使用しています。何らかの理由で、静的なファイルがフロントコントローラに当たっているようですindex.phpなぜこの.htaccessファイルはスタティックファイルをフロントコントローラにルーティングしていますか?

例:https://example.com/apple-touch-icon.pngは、応答ヘッダーがX-Powered-By:PHP/5.5.9-1ubuntu4.3を含むことがわかるように、フロントコントローラーによって処理されています。

誰でも問題を見つけることができますか?

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase/

    ### Force SSL 
    RewriteCond %{HTTP:X-Forwarded-Proto} !https 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

    ### Canonicalize codeigniter URLs 

    # If your default controller is something other than 
    # "welcome" you should probably change this 
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$/[L,R=301] 
    RewriteRule ^(.*)/index/?$ $1 [L,R=301] 

    # Removes trailing slashes (prevents SEO duplicate content issues) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ $1 [L,R=301] 

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

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

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

    # Without mod_rewrite, route 404's to the front controller 
    ErrorDocument 404 /index.php 

</IfModule> 
+1

「ErrorDocument 404/index.php」をコメントアウトして同じ 'png'ファイルをリロードする – anubhava

+1

それは原因です!おそらくあなたは正しい答えとしてマークすることができるように答えを加えることができます。なぜIfModule !mod_rewrite.c'は実行されましたか? – Abs

+1

奇妙な... ''は実行しないでください!そして、それが実行された場合、反対側のブロック( '')も実行できませんか?しかし、 'ErrorDocument'が処理された場合、' .png'が存在していればそれは問題ではありません。しかし、あなたはプロキシの背後にあります...それはそれと関係がありますか?ちなみに、 'RewriteCond'ディレクティブが常に失敗するため、' REQUEST_URI'サーバ変数は常にスラッシュ_で始まりますので、ユーザがシステムフォルダへのアクセスを削除するルールは何もしません。 – MrWhite

答えて

2

いくつかのリソースすなわちイメージは、JSやCSSファイルが見つからない場合、あなたのErrorDocumentディレクティブは、この(ロードindex.phpを引き起こしていることが表示されます

あなたはこの動作を回避するために、このディレクティブをコメントアウトすることができます。

ErrorDocument 404 /index.php 
+0

しかし、これはおそらく、mod_rewriteが有効でなく、静的リソースが存在しない場合にのみ問題になるでしょうか? – MrWhite

+1

ああそうだよ。少なくとも "ErrorDocument"コードは 'mod_rewrite'がロードされていないときにのみ起動します*何とか*。 – anubhava

+1

これが問題でした。なぜ私の条件ブロックが失敗するのかを調査する必要があります。今のところ、これは最初の質問を解決しますが、ありがとう! – Abs

関連する問題