LAMP和LNMP去除index.php访问

时间:2023-12-12 19:49:08

使用TP或者Laravel开发的时候,后时候会遇到需要加index.php才能正常访问

LAMP解决方法

    1.修改配置

      打开配置文件(如:httpd.conf),找到你网站根目录的配置,将AllowOverride这项改为all

    2.重启服务

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all 这个就是
Require all granted
</Directory>

  LNMP解决办法

    1.编辑配置文件

      

vi /usr/local/nginx/conf/vhost/虚拟主机名字.conf
#注释
include enable-php.conf (或者直接dd删除)
#添加
include enable-php-pathinfo.conf; #注意后面必须带分号
#在server段添加
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$ last;
}
}

完整配置文件

server
{
listen ;
#listen [::]:80;
server_name www.wangnana.cn wangnana.cn;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.wangnana.cn/public; include rewrite/none.conf;
#error_page 404 /404.html; # Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
     #这一段
include enable-php-pathinfo.conf;
#include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} location ~ /.well-known {
allow all;
} location ~ /\.
{
deny all;
}
#这一段
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$ last;
}
} access_log /home/wwwlogs/www.wangnana.cn.log;
}

  

  2.重启服务