[英]Nginx Wordpress Permalinks without index.php
我的Nginx使用php 7 fpm运行。 我的Wordpress永久链接是使用/%postname%/
。 假设我的域名是example.com
我想要这样的永久链接: example.com/postname/
但这会导致错误。 我可以通过以下链接找到该帖子: example.com/index.php?postname/
如何摆脱index.php?
在链接中?
我的Nginx配置
server {
server_name localhost;
root /var/www/;
index index.html index.htm index.php;
location ~\.php$ {
try_files $uri =404;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param REQUEST_URI $args;
}
location / {
try_files $uri $uri/ /index.php$args;
}
location /wordpress/ {
try_files $uri $uri/ /wordpress/index.php?$args;
}
}
您的问题暗示WordPress安装在location /
,所以我不确定为什么您也有location /wordpress
。
您的配置存在一些问题。
REQUEST_URI的值应设置为$request_uri
,这可能已经是fastcgi_params
文件中的默认值。 这是index.php
用于解码漂亮的永久链接的参数。
删除行fastcgi_param REQUEST_URI $args;
。
您的try_files
语句缺少?
。 使用以下任一方法:
try_files $uri $uri/ /index.php?$args;
要么:
try_files $uri $uri/ /index.php;
我发现使用WordPress不需要将$args
传递到/index.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.