【问题标题】:using framework and simple.php page want to remove .php from simple page使用框架和 simple.php 页面想从简单页面中删除 .php
【发布时间】:2017-05-18 10:38:30
【问题描述】:
我有一个 CodeIgniter 安装和一个单独的 simple.php 文件,它位于框架目录之外。我想从simple 页面中删除.php 扩展。
目前,我正在使用从 CodeIgniter 请求中删除 index.php 的代码,但它不能在框架之外工作:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
如何删除.php 扩展?
【问题讨论】:
标签:
php
.htaccess
codeigniter
mod-rewrite
url-rewriting
【解决方案1】:
我想你的意思是你有一个 CodeIgniter 安装在,例如,/foo/bar/my-ci-app 里面有一个.htaccess 文件。
您还有一个simple.php 位于/foo/bar/simple.php(在框架之外)。现在您想从该simple.php 文件中删除.php 扩展名,对吧?
htaccess file 中定义的指令仅对其驻留目录及其子目录有效。由于您的 simple.php 文件不在 CodeIgniter 安装范围内,因此该 htaccess 文件对您没有用处,因为它的指令不会向后生效。
您需要另一个位于foo/bar/.htaccess 中的simple.php 文件旁边的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