Php Nginx重写规则未按预期工作

Php Nginx重写规则未按预期工作,php,nginx,url,post,Php,Nginx,Url,Post,我有一个网站 https://dev.mywebsite.com/index.php?album=portraits 它基于POST值动态显示相册 我想将此URL重写为: https://dev.mywebsite.com/portraits 但是我的Nginx重写规则不起作用。当我输入https://dev.mywebsite.com/index.php?album=portraits。输入https://dev.mywebsite.com/portraits 我不知道我做错了什么 这是我目前

我有一个网站
https://dev.mywebsite.com/index.php?album=portraits
它基于POST值动态显示相册

我想将此URL重写为:
https://dev.mywebsite.com/portraits

但是我的Nginx重写规则不起作用。当我输入
https://dev.mywebsite.com/index.php?album=portraits
。输入
https://dev.mywebsite.com/portraits

我不知道我做错了什么

这是我目前正在尝试使用的代码:

location / {
        rewrite ^/(.*)$ /album.php?album=$1 last;
}
我也试过:

location = /portraits { 
        rewrite ^/portraits?$ /index.php?album=portraits break; 
}
这是:

location = /album { 
        rewrite ^album/([a-z]+)/?$ album.php?album=$1 break; 
}
这是我正在使用的整个nginx站点配置文件:

server {
        listen 80 default_server;
        listen 443 ssl;                                         
        root /config/www;
        index index.php index.htm index.html;
        server_name dev.mywebsite.com;

        ssl_certificate /config/keys/cert.crt;
        ssl_certificate_key /config/keys/cert.key;

        client_max_body_size 0;

        location / {
                try_files $uri $uri/ /index.html /index.php?$args =404;
        }
    location / {
                rewrite ^/(.*)$ /album.php?album=$1 last;
        }

    location ~ \.php$ {
                #fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;

        }
}
如果您真正拥有的文件是
index.php
,那么您可以使用以下内容重写(无需任何额外的
位置
):


保留
位置~\.php${
当然:)

你不能有两个
location/
块。使用
nginx-t
测试你的配置文件。php文件名为
album.php
还是
index.php
?谢谢你,我不知道我不能有两个。我使用的文件是index.php。但我也尝试用album的另一种方式设置它.php,因为一切都不起作用。谢谢你,这起作用了!我把
肖像画
分别改为
([a-z]+)
$1
,所以它对我所有的相册都起作用。
rewrite ^/portraits$ /index.php?album=portraits last;