Codeigniter を使用していますが、URL の index.php 部分を省略したいと考えています。ウェブルートで次のような .htaccess を使用してこれを行うことができました。
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|css|jpg|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
と使用
$config['index_page'] = '';
これは機能し、subdomain.example.com/class/method のような URL は期待どおりに機能します。
ここで、ビューのスタイルシートと画像を webroot の下の「style」というフォルダーに追加し始めました。ただし、それらにアクセスしようとすると、エラー 404 が発生します。ビューでそれらを複数の方法で使用しようとしました。
<img src="/style/img.jpg">
<img src="style/img.jpg">
<img src="<?php echo base_url('/style/img.jpg');?>">
<img src="http://subdomain.example.com/style/img.jpg">
<img src="<?php echo base_url();?>style/img.jpg">
base_url() はhttp://subdomain.example.com/を提供します。役に立つ情報であれば、スタイル ファイルのユーザー mod は 755 に設定されています。私の推測では、.htaccess が何らかの形でこれらをブロックしていると思います。私はそれをグーグルで検索しましたが、多くの人が同様の問題を抱えているようですが、画像を使用して index.php を省略するのに役立つ答えを見つけることができませんでした。これは、これらの回答を検索した後に htaccess で取得した場所ですが、それでも画像にはうまくいきません:
#Enable mod rewrite
RewriteEngine On
#Removes access to CodeIgniter 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
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|style|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
私はアイデアがありません。