2017-01-04 34 views
0

我有一個CodeIgniter安裝和一個單獨的simple.php文件,它位於框架目錄之外。我想從simple頁面刪除.php擴展名。使用框架和simple.php頁面要從簡單頁面中刪除.php

目前,我使用此代碼從笨請求刪除index.php,但它不工作的框架之外:

RewriteOptions inherit 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$1 [PT,L] 

我如何刪除.php擴展?

回答

0

我想你的意思是說你有一個CodeIgniter安裝在例如/foo/bar/my-ci-app其中有一個.htaccess文件。

您還有一個simple.php住在/foo/bar/simple.php(框架之外)。現在你想從simple.php文件中刪除.php擴展名,對吧?

htaccess file中定義的指令只對其駐留目錄及其子目錄有效。由於您的simple.php文件不在CodeIgniter安裝中,因此該htaccess文件對您沒有用處,因爲其指令不會生效。

您需要另一個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