Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

WBOY
Release: 2016-06-06 20:11:07
Original
1125 people have browsed it

Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

最近由于阿里云主机内存过低,使用 Apache 时不时抽风,所以换成 Nginx,不过伪静态规则难倒了我。按照官网介绍主要添加以下规则即可。

<code>location / {
    try_files $uri $uri/ /index.php?$args;
}</code>
Copy after login
Copy after login

不过实测只能支持

<code>//支持这类目录形式
http://www.domain.com/category/tag
http://www.domain.com/category/postname

//不支持带后缀
http://www.domain.com/category/postname.html</code>
Copy after login
Copy after login

现在访问带后缀的地址都是 404,如果把固定链接的形式改成截图中的目录形式或?p=id都是正常访问,请问以上有错么?或者还需要哪些方面的设置?

回复内容:

Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

最近由于阿里云主机内存过低,使用 Apache 时不时抽风,所以换成 Nginx,不过伪静态规则难倒了我。按照官网介绍主要添加以下规则即可。

<code>location / {
    try_files $uri $uri/ /index.php?$args;
}</code>
Copy after login
Copy after login

不过实测只能支持

<code>//支持这类目录形式
http://www.domain.com/category/tag
http://www.domain.com/category/postname

//不支持带后缀
http://www.domain.com/category/postname.html</code>
Copy after login
Copy after login

现在访问带后缀的地址都是 404,如果把固定链接的形式改成截图中的目录形式或?p=id都是正常访问,请问以上有错么?或者还需要哪些方面的设置?

终于找到可以用的规则了,之前的规则可能是某些设置或 index.php 权限问题导致无法定位到正确的地址,用以下规则解决了。

<code>rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
if (!-e $request_filename) {
    rewrite ^.+?(/wp-.*) $1 last;
    rewrite ^.+?(/.*\.php)$ $1 last;
    rewrite ^ /index.php last;
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!