AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 787291
Accepted
physalis
physalis
Asked: 2016-07-01 16:58:27 +0800 CST2016-07-01 16:58:27 +0800 CST 2016-07-01 16:58:27 +0800 CST

nginx子目录通配符重写

  • 772

我已经在我的 nginx 服务器上设置了一个服务器块,例如域testsite.com。我希望能够将单独的 WordPress 安装安装到根文件夹的直接子文件夹中,例如 /var/www/html/testsite.com/ childfolder1、 /var/www/html/testsite.com/ childfolder2等,所以他们可以通过 testsite.com/ childfolder1、 testsite.com/ childfolder2等访问。

创建重定向的手动方法是像这样插入它:

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

并为每个站点重复它。使用location /仅涵盖根目录。有没有办法创建一个(正则表达式?)通配符规则,上面写着:“对于每个直接子目录,应用这个 try_files 命令”(这对于 WordPress 来说显然总是相同的,只是文件夹名称发生了变化)?

location /*anydirectsubdirectory* {
    index index.php;
    try_files $uri $uri/ /*anydirectsubdirectory*/index.php?$args;
}
rewrite nginx directory wildcard
  • 2 2 个回答
  • 6873 Views

2 个回答

  • Voted
  1. Best Answer
    cnst
    2016-07-03T18:55:08+08:002016-07-03T18:55:08+08:00

    我无法证明您想要做的事情是否有效,但下面是将您的“伪代码”转换为实际的 nginx 配置(如果同样的复制粘贴解决方案对您有用,这也应该继续有效)。

    location ~ /(?<anydirectsubdirectory>[^/]+) {
        index index.php;
        try_files $uri $uri/ /$anydirectsubdirectory/index.php?$args;
    }
    
    • 4
  2. JohnsonGoey
    2016-07-01T22:12:45+08:002016-07-01T22:12:45+08:00

    试试这个~

    server { listen 80; server_name example.com; charset utf-8; access_log logs/xxxxxx.access.log;

    root   /var/www/html;
    
    index index.php;
    location = / { return 301 /cn/; }
    
    location / {
        try_files $uri $uri/ /cn/index.php?q=$uri;
    }
    location /en {
        try_files $uri $uri/ /en/index.php?q=$uri;
    }
    location /my {
        try_files $uri $uri/ /my/index.php?q=$uri;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    }
    

    }

    • -1

相关问题

  • 阿帕奇虚拟主机

  • IIS 7 中的 URL 重写

  • IIS7 请求跟踪日志上的 URL_CHANGED 事件是什么?

  • 如何强制我的网址始终以 www 开头?

  • mod_rewrite 不转发 GET 参数

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve