子目录下的nginx重写规则 [英] nginx rewrite rule under a subdirectory

查看:30
本文介绍了子目录下的nginx重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在子目录下运行 nginx 的 WordPress 站点.如何在子目录中编写重写规则?或者任何人都可以转换这个Apache重写规则吗?我到处搜索有关 nginx 重写规则的信息,但没有任何效果!

I have a WordPress site running nginx under a sub-direcotry. how can i write rewrite rules in a sub-directory? or can anyone please convert this Apache rewrite rule? I searched everywhere about nginx rewrite rules but nothing worked!

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

感谢任何帮助,谢谢

推荐答案

尽量用这个,别忘了替换root路径!

try to use this, and please don't forget to replace root path!

location /main/ {
   root /full/path/from/root/main/;
   try_files $uri $uri/ /index.php?$args;
}

我已经在我的主机上的文件夹/main 中设置了 wordpress,并且可以使用下一个设置:

I've set wordpress on my host in folder /main and got it's working with next settings:

location /main {
        index index.php;
        try_files $uri $uri/ /main/index.php?q=$uri;
}
root /path/to/webroot;

这篇关于子目录下的nginx重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆