2011-05-09 135 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