我有一个CodeIgniter安装和一个单独的simple.php
文件,它位于框架目录之外。我想从.php
页面删除simple
扩展名。
目前,我正在使用此代码从CodeIgniter请求中删除index.php
,但它不在框架之外工作:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
如何删除.php
扩展程序?
答案 0 :(得分:0)
我想你的意思是你有一个CodeIgniter安装,例如.htaccess
,其中有一个simple.php
文件。
您还有/foo/bar/simple.php
驻留在.php
(框架之外)。现在您要从simple.php
文件中删除simple.php
扩展名,对吗?
htaccess file中定义的指令仅对其驻留目录及其子目录有效。由于您的simple.php
文件不在CodeIgniter安装之外,因此该htaccess文件对您没用,因为它的指令不会向后生效。
您需要位于foo/bar/.htaccess
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
文件旁边的另一个htaccess文件。您需要删除php扩展的重写规则如下:
new