【发布时间】:2015-07-08 18:43:35
【问题描述】:
我将 Nginx 与我的网络服务器一起使用,并且不完全理解重写是如何在这里工作的。我让它在 Apache 上运行。
我使用基于 MVC 的 PHP 项目,我想像使用 Apache 一样使用干净的 URL。
www.domain.com/index.php?url=home/index 工作正常。
www.domain.com/home/index 不起作用。
正如你所看到的,我想要像上一个一样干净的 URL。
我已经尝试了几次重写,不知道我应该使用 try_files 还是重写。但我猜它是在我之后重写的。
正如我所说,我仍在学习重写。 我的服务器块如下所示:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/pub/;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/index.php?$arg_url /$arg_url permanent;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
我认为我的重写块是有道理的,但我想它没有。尝试了几次重写,我得到 500 或 404 错误。正如我所说,我还没有得到重写。需要一些帮助才能开始。
提前致谢。
【问题讨论】:
标签: php mod-rewrite nginx request-uri