Post Name Permalink setup gives 404 error inside sub-directory

I have setup my first AWS EC2 account and installed nginx. The root is usrsharenginxhtml. I have installed WordPress

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

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

Share Improve this question edited Aug 23, 2017 at 14:37 Subrata Sarkar asked Aug 23, 2017 at 13:44 Subrata SarkarSubrata Sarkar 2395 silver badges16 bronze badges 3
  • htaccess files only work on Apache servers, they'll do nothing for nginx servers. You'll need to modify nginx configs instead – Tom J Nowell Commented Aug 23, 2017 at 14:31
  • Yes, after some research I have come to know that nginx has no connection with .htaccess! I am trying to set things up for nginx. @Hasin Hyder is trying to help me out! – Subrata Sarkar Commented Aug 23, 2017 at 14:39
  • proptip: steal the nginx configs from VVV, take special note of github/Varying-Vagrant-Vagrants/VVV/blob/develop/config/… – Tom J Nowell Commented Aug 23, 2017 at 14:42
Add a comment  | 

1 Answer 1

Reset to default 2

It's happening because Nginx doesn't interpret rewrite rules like Apache via mod_rewrite. You need to change your nginx vhost config file (nginx site config file, i.e /etc/nginx/sites-enabled/your-site-config.conf file)

Add the following line inside server block

location / {
            try_files $uri $uri/ /index.php?$args; 
}

if the location / is already present, then remove the existing try_files directive and replace it with the following line

try_files $uri $uri/ /index.php?$args;

Now restart or reload Nginx and your problem will be gone. Here is a good article link regarding this https://www.cyberciti.biz/faq/how-to-configure-nginx-for-wordpress-permalinks/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745138261a4613307.html

相关推荐

  • Post Name Permalink setup gives 404 error inside sub-directory

    I have setup my first AWS EC2 account and installed nginx. The root is usrsharenginxhtml. I have installed WordPress

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信