【发布时间】:2018-01-18 06:46:29
【问题描述】:
所以我现在在nginx中有这样的配置:
autoindex off;
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
现在,我想要一些“特别”的东西。我想获取一个 url (http://project2.local/camera?camera_id=1) 重写为http://project2.local/camera/1 我已经尝试过这段代码;
location / {
rewrite ^/?camera\.php$ /camera/%1? redirect;
}
location /camera {
rewrite ^/camera/([^/]*)$ /camera.php?camera_id=$1 break;
}
但是当我导航到那个地方时会下载一些空的东西。我在这里做错了什么?
【问题讨论】:
标签: nginx url-rewriting