![nginx:所有流量到 index.php](https://linux22.com/image/528774/nginx%EF%BC%9A%E6%89%80%E6%9C%89%E6%B5%81%E9%87%8F%E5%88%B0%20index.php.png)
如何将所有流量发送到单个 index.php 文件,无论路径或域如何?在 nginx.conf 中执行此操作的最快方法是什么?try_files?
感谢您的见解
答案1
# Assuming you want static files as well
server {
listen 80 default_server; # Use default; instead if you're still on 0.7.x.
try_files $uri /index.php;
# Standard PHP location block here.
}
# Assuming you do not want static files as well
server {
listen 80 default_server; # Use default; instead if you're still on 0.7.x.
location = /index.php {
# Fastcgi/proxy pass
}
location / {
rewrite ^ /index.php last;
}
}
答案2
我想到的第一个答案是,你可以把它放在对你最有利的地方。
rewrite .* /index.php;