【问题标题】:Nginx rewrite all directory requests to index.phpNginx 将所有目录请求重写为 index.php
【发布时间】:2011-08-16 21:54:53
【问题描述】:

好的,我在 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 引导程序。

location /dojump 块应该用于我拥有的出站重定向脚本。我想捕获参数并将它们传递给 index.php 脚本

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

通过 dojumps 文件夹中的这个简单的 .htaccess 行与 apache 配合使用

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

但是,我在 错误日志

中收到一个 nginx 错误
/usr/share/nginx/www/dojump/index.php/cnn.com" failed (20: Not a directory)

有什么帮助吗?

谢谢

【问题讨论】:

标签: redirect nginx


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2013-01-01
    • 2012-12-09
    相关资源
    最近更新 更多