apache / nginx:.htaccess重写转换混乱

时间:2011-05-09 06:25:38

标签: apache mod-rewrite url-rewriting nginx rewrite

我正在尝试从Apache重写一个.htaccess规则,以便在Nginx服务器上使用。

RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php/$1 [L]

这是我的工作,但是一些更好的方向将非常受欢迎。我可以点击索引,它加载好并浏览到资产文件夹,但更深层次的链接不起作用(PHP程序从URL中提取变量来构建数据库查询)。我知道我很接近..感谢任何回复。

location / {
  index index.php;
}
location /$ {
  rewrite ^/(.*)$ /index.php/$1 last;
}
location /index.php {
  root html;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
  include fastcgi_params;
}

1 个答案:

答案 0 :(得分:0)

我认为这些规则会将不属于/ assets的所有内容发送到/index.php。我想这会做你想要的。此外,它将root和index指令移动到服务器中,这是将它们设置为所有位置的默认值。

# set server defaults directly in server context
root /usr/share/nginx/html;
index index.php;

# location / is a fallback for any request that doesn't match
# a more specific location
location / {
  rewrite ^ /index.php$uri last;
}

# Serve content under /assets from disk
location /assets {
}

# Extract path info and send /index.php for processing
location /index.php {
  fastcgi_split_path_info ^(/index.php)(.*)
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param PATH_INFO $fastcgi_path_info;
  fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  fastcgi_pass 127.0.0.1:9000;
}