什么是nginx重写规则重定向我的wordpress永久链接结构从/%category%/%postname%/
到/%postname%/
?NGINX重写规则为干净URL
6
A
回答
5
2
总之,您需要让NGINX知道如果该文件不存在,不会抛出404错误,而是请拨打index.php
。 Wordpress足够聪明,可以将URL解析为参数,并提供正确的页面。
加入这个片段在你服务器的配置块:
location/{
try_files $uri $uri/ /index.php?$args;
}
这里是nginx.org一个完整的例子:
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
## Your website name goes here.
server_name domain.tld;
## Your only path reference.
root /var/www/wordpress;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location/{
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
+0
注意“非默认永久链接”也包括类别链接。在我的初始设置中,这行读取'try_files $ uri $ uri/= 404';用'/index.php?$ args'替换'= 404'是让我的分类链接重新运行的必要步骤。 – rsfinn
相关问题
- 1. 简单的nginx重写干净的URL
- 2. nginx的URL重写规则
- 3. Nginx的URL重写规则
- 4. Nginx的 - URL重写规则
- 5. Nginx重写干净URL的规则(问题与CSS和JS呈现)
- 6. nginx重写为干净的网址
- 7. 错误500或重写规则得到干净的URL
- 8. Nginx重写规则
- 9. 重写规则nginx
- 10. Nginx - 重写规则
- 11. NGINX动态URL的重写规则
- 12. nginx的设置URL重写规则
- 13. 将apache htaccess重写规则转换为nginx重写规则
- 14. 重写规则为URL
- 15. 相对Nginx重写规则
- 16. 重写规则Apache到nginx
- 17. htaccess到nginx重写规则
- 18. NGINX重写规则排除
- 19. Nginx的重写规则
- 20. Nginx重写规则+ CSS&JS
- 21. Apache-Nginx重写规则
- 22. Nginx的重写规则
- 23. Apache到nginx重写规则
- 24. nginx的重写规则
- 25. Nginx的重写规则saml
- 26. 重写规则fir NGINX
- 27. 在Nginx的重写规则
- 28. nginx的重写规则
- 29. Nginx的重写规则
- 30. nginx重写app api规则
谢谢,文章是有用 – Joel
谢谢,有同样的问题 –