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

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

问题描述

我有一个子direcotry下运行nginx的一个Word preSS站点。
我怎么能写在一个子目录重写规则?
或任何人都可以请转换此阿帕奇重写规则?我到处找工作有关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>

任何帮助AP preciated,谢谢

any help appreciated, thanks

推荐答案

尝试使用这一点,请不要忘记更换根路径!

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;
}

我已经把我的文件夹/主主机上的字preSS,得到它的工作与下一设置:

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天全站免登陆