使用框架和simple.php页面想从简单的页面中删除.php

时间:2017-01-04 07:50:29

标签: php .htaccess codeigniter mod-rewrite url-rewriting

我有一个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扩展程序?

1 个答案:

答案 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