帖子名称固定链接设置在子目录内出现404错误

时间:2017-08-23 作者:Subrata Sarkar

I have setup my first AWS EC2 account and installed nginx. The root is /usr/share/nginx/html. I have installed WordPress as a sub-folder called cooking under root. the site address is http://54.226.50.133/cooking.

As long as I have permalink setup as Plain, pages are coming up ok, but when I update permalink structure to use Post Name, I get 404 error.

http://54.226.50.133/cooking/?p=1 - runs OK http://54.226.50.133/cooking/hello-world/ - gives 404

Location of WordPress installation (cooking): /usr/share/nginx/html/cooking
Location of .htaccess file: /usr/share/nginx/html/cooking/.htaccess
Content of .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I am not sure but multisite might be a solution but I don\'t want to go this far right now, rather I want to keep it simple at the beginning. Basically I will need more sub-folders (different WP installations for different sites) like this under usr/share/nginx/html folder for demonstration purpose.

Please suggest me the right way to achieve this.

UPDATE
I have Permalink setting set to Post Name for the moment, so http://54.226.50.133/cooking/?p=1 will give 404 right now, which is OK. But http://54.226.50.133/cooking/hello-world/ still ends up with 404.

Screenshot
enter image description here

1 个回复
SO网友:Hasin Hayder

之所以会发生这种情况,是因为Nginx不会像Apache那样通过mod\\u rewrite来解释重写规则。您需要更改nginx vhost config文件(nginx site config文件,即/etc/nginx/sites enabled/your-site-config.conf文件)

在服务器块内添加以下行

location / {
            try_files $uri $uri/ /index.php?$args; 
}
如果location / 已存在,然后删除现有的try\\u files指令,并将其替换为以下行

try_files $uri $uri/ /index.php?$args;
现在重新启动或重新加载Nginx,您的问题就会消失。这里有一个很好的文章链接https://www.cyberciti.biz/faq/how-to-configure-nginx-for-wordpress-permalinks/

结束

相关推荐

Change Taxonomy Permalinks

我有自定义帖子,我创建了一个显示所有自定义帖子的页面。示例:www.example.com/archive-page我想知道是否可以更改与此自定义帖子相关的类别和标签的永久链接。现在我有:www.example.com/my-custom-post-type-cats/my-category-1www.example.com/my-custom-post-type-tags/my-tag-1</我想要这样的东西:www.example.com/archive-page?category=1www.e