Nginx 将所有目录请求重写为 index.php [英] Nginx rewrite all directory requests to index.php
问题描述
好吧,我对 Nginx 有点了解,我浏览了这里,无法拼凑出一个答案.所以这就是我得到的
Okay I'm kind of n00b on Nginx, and I've browsed through here and couldn't piece together an answer. SO here is what i got
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 引导程序.
This is on a wordpress setup the first location block should pass all file requests to the wordpress bootstrap.
location/dojump
块应该用于我拥有的出站重定向脚本.我想捕获参数并将它们传递给 index.php 脚本
the location /dojump
block is supposed to be for an outbound redirect script i have. I want to catch the arguments and pass them to the index.php script
喜欢/dojump/cnn.com到/dojump/index.php/cnn.com
like /dojump/cnn.com to /dojump/index.php/cnn.com
它与 apache 一起使用 dojumps 文件夹中的这个简单的 .htaccess 行
it works with apache with this simple .htaccess line inside the dojumps folder
RewriteRule ^(.*)$ index.php/$1 [L]
但是,我在错误日志
/usr/share/nginx/www/dojump/index.php/cnn.com" failed (20: Not a directory)
有什么帮助吗?
谢谢
推荐答案
尝试将 url 作为 GET 参数传递.
Try passing the url as a GET parameter.
rewrite ^/dojump/(.*)$ /dojump/index.php?url=$1 break;
这篇关于Nginx 将所有目录请求重写为 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!