Nginx禁止运行php并跳转到其他页面

PHP编程技术 网络投稿 2021-12-30 04:41 834 0

我想让https://i1.100024.xyz 跳转到 https://img.178d.com 但同时可以让 https://i1.100024.xyz 的静态文件可以访问,也就是说禁止 https://i1.100024.xyz 的php运行,如何操作呢?
其实很简单
只要添加:

location ~ .*\.(php)${
    return 301 https://img.178d.com$request_uri;  }
Shell

如果开启了ssl,也需要在ssl部分添加:

location ~ .*\.(php)${
    return 301 https://img.178d.com$request_uri;  }
Shell

如果想禁止php的运行可以这样写:

location ~ .*\.(php)$ {deny all;}
Shell