TP 5は隠し入口indexを配置する.phpファイル

3836 ワード

非表示のindex.php
PS:ここでいうエントリファイルとは、パブリック/indexを指す.phpファイル、プロファイルはこのディレクトリの下にあります
URLアドレスのエントリファイルindex.phpは削除できますが、WEBサーバの書き換えルールを追加して構成する必要があります.Apacheを例にとると、ファイルエントリを必要とする同級に.htaccessファイル(公式デフォルトではこのファイルが付属しています)を追加します.内容は以下の通りです.

Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

phpstudyを使用する場合、ルールは次のとおりです.
 
Options +FollowSymlinks -Multiviews 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] 

index.php public の場合、ルールは次のとおりです.
 
Options +FollowSymlinks -Multiviews 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ public/index.php [L,E=PATH_INFO:$1] 


次のURLアドレスでアクセスできます
http://tp5.com/index/index/index
http://tp5.com/index/index/hello
apacheバージョンで上記の方法でindex.phpを正常に隠すことができない場合は、.htaccessファイルを次の方法で構成してみてください.

Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]


英語のNginx環境であれば、教育はNginx.confに追加できます.
location / { // …..      
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    }
}