たとえば、/foo/bar/my-ci-app
にCodeIgniterインストールがあり、その中に.htaccess
というファイルがあるとします。
また、/foo/bar/simple.php
(フレームワークの外側)にあるsimple.php
もあります。そして、そのsimple.php
ファイルから.php
拡張子を削除したいのですが、
htaccess fileで定義されたディレクティブは、そのディレクトリとそのサブディレクトリにのみ有効です。 simple.php
ファイルはCodeIgniterのインストール外にあるため、htaccessファイルはそのディレクティブが後方に反映されないため、あなたのためのものではありません。
simple.php
ファイルの横にある別のhtaccessファイルがfoo/bar/.htaccess
に存在する必要があります。 PHP拡張モジュールを削除する必要がある書き換えルールは次のとおりです:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase/
# Just to be sure that these rules has no conflict with your
# codeigniter rewrite rules, we're gonna discard the following
# rewrite rule if the request uri contains its directory name.
RewriteCond %{REQUEST_URI} !my-ci-app
# If the corresponding php file exists
RewriteCond %{REQUEST_FILENAME}.php -f
# And the request uri does not contain a php file format,
# for example, whatever.php, rewrite the request to a file
# named as %{REQUEST_FILENAME} (simple in your case) and add
# a .php extension to it.
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
</IfModule>
## Results
# simple => simple.php
# example => example.php