TP5配置隐藏入口index.php文件

隐藏tp入口文件index.php

官方代码:

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]

如果你使用的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;
}}
其中
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]和
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
亲测好用

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注