nginx:所有流量到 index.php

nginx:所有流量到 index.php

如何将所有流量发送到单个 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;

相关内容