2011-05-09 138 views
0

我想重写Apache中的.htaccess规则以用于Nginx服务器。apache/nginx:.htaccess重写转换混乱

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; 
} 

回答

0

我认为这些规则会将/ assets下的所有内容都发送到/index.php。我认为这会做你想做的事。此外,它将根和索引指令移动到服务器,这是它们应该被设置为所有位置的默认位置。

# 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; 
} 
+0

邪恶的,这个伟大的作品!现在唯一的问题是查询字符串没有正确地传递给ajax页面,并且它导致整个index.php重新加载到ajax的区域内。有关于此的任何想法? – wunderbar 2011-05-09 15:23:58

+0

重写位置/应自动保留查询字符串。你编辑过你的fastcgi_params文件吗?它应该有一行:fastcgi_param QUERY_STRING $ query_string; – kolbyjack 2011-05-09 20:19:36