【问题标题】:nginx redirects to subfolder for prettier linksnginx 重定向到子文件夹以获得更漂亮的链接
【发布时间】:2014-05-23 01:00:13
【问题描述】:

我有一个关于 nginx 重定向/try_files 的问题:
我有一个网站(由 ISPConfig3 管理的虚拟主机)位于 www.XXXYYY.com
根目录下有文件夹,index.php等。
我希望www.XXXYYY.com/folder21/public/309273.php 中的某些文件可以通过www.XXXYYY.com/309273 访问(以获得更漂亮的链接)。

但是,我尝试过的所有东西要么根本不起作用,要么 .php 文件被下载而不是由 PHP-FPM 处理......

这是我目前在 ISPConfig3 中尝试的 nginx vhost 指令:

这是由 ISPConfig3 设置的:

location ~ \.php$ {
        try_files @php;
    }

location @php {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9026;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

这是我在 vhost 文件底部添加的部分:

location / {
   try_files $uri $uri/ /folder21/public/$uri.php /index.php =404;
}

location /folder21/       { internal; }
location /folder21/public/ {
    try_files $uri $uri/ $uri.php;
}

对此的任何帮助表示赞赏!

【问题讨论】:

  • 你有一个块来捕获 php 文件吗?
  • @MohammadAbuShady 感谢您指出这一点!我刚刚添加了 php 块!

标签: php redirect nginx vhosts pydio


【解决方案1】:

这就是我对 pydio 的最终结果:

location /conf/       { deny all; }
location /data/       { internal; }
location /data/public/ {
    try_files $uri $uri/ $uri.php?$args;
    rewrite ^/data/public/([a-z0-9]+)-([a-z]+)$ /data/public/$1.php?lang=$2 last;
}
location ^~ /share/ {
    rewrite ^/share/(.*)$ /data/public/$1 last;
}

/data/public 中的 PHP 文件现在通过 /share 提供,无需 .php 结尾。
格式为例如的文件/data/share/XYZ123-en 正在重写为/data/share/XYZ-123.php?lang=en

【讨论】:

    猜你喜欢
    • 2012-01-19
    • 2017-03-09
    • 2014-09-02
    • 2014-05-24
    • 2017-05-10
    • 2013-03-26
    • 2013-01-10
    • 2013-03-13
    • 2015-09-23
    相关资源
    最近更新 更多