微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

redirect – Nginx将所有目录请求重写为index.php

好吧,我在Nginx上有点n00b,而且我已经浏览过这里,无法拼凑出一个答案.这就是我得到的

server {
root /usr/share/Nginx/www;
index index.PHP index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html


        if (-f $request_filename) {  
            expires 30d;  
            break;  
        }  
        if (!-e $request_filename) {  
            rewrite ^(.+)$/index.PHP?q=$1 last;  
        }  
}

location /dojump {
    rewrite ^/dojump/(.*)$/dojump/index.PHP/$1 break;
}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.PHP(.*)${
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.PHP;
    include fastcgi_params;
}

这是在wordpress设置上,第一个位置块应该将所有文件请求传递给wordpress bootstrap.

location / dojump块应该是我的出站重定向脚本.我想捕获参数并将它们传递给index.PHP脚本

喜欢/dojump/cnn.com
到/dojump/index.PHP/cnn.com

它与apache一起使用dojumps文件夹中的这个简单的.htaccess行

RewriteRule ^(.*)$index.PHP/$1 [L]

但是,我在错误日志中收到Nginx错误

/usr/share/Nginx/www/dojump/index.PHP/cnn.com" Failed (20: Not a directory)

有帮助吗?

谢谢

解决方法:

尝试将url作为GET参数传递.

rewrite ^/dojump/(.*)$/dojump/index.PHP?url=$1 break;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐