1

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]

私はアイデアがありません。

4

2 に答える 2

1

.htaccessindex.php を削除するためのファイルをこれに変更してみてください

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|ref_doc|media|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

これはうまくいくはずです

于 2013-10-28T15:12:21.733 に答える
0

次のようなものを書き換えルールに追加してみてください (htaccess の最後に):

 RewriteRule directoryname - [L]

申し訳ありませんが、今は自分でテストできません。

于 2013-10-28T15:08:54.003 に答える