apache与nginx如何隐藏入口文件

Posted 孤狼程序员

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache与nginx如何隐藏入口文件相关的知识,希望对你有一定的参考价值。

不管是为了伪静态还是为了url美观,我们经常需要隐藏掉项目的入口文件index.php

那么如何隐藏呢?详细流程如下:


Apache写法(Apache/conf/httpd.conf)

首先需要开启配置模块

LoadModule rewrite_module modules/mod_rewrite.so(去掉前面#号注释)

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(Uploads)
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>


nginx写法

location / {	if (!-e $request_filename){
		rewrite ^/index.html/?$ /index.php?s= last;
		rewrite  ^(.*)$  /index.php?s=$1 last;		break;
	}
}


修改完成记得重启服务器

以上是关于apache与nginx如何隐藏入口文件的主要内容,如果未能解决你的问题,请参考以下文章

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

记thinkphp5在Nginx环境下多入口 隐藏入口文件后缀

apache隐藏入口文件index.php

thinkphp5.0如何隐藏index.php入口文件

nginx隐藏入口文件index.php

TP5配置隐藏入口index.php文件,Apache/phpstudy