nginx [emerg] unknown“0”变量

时间:2014-09-17 10:29:46

标签: .htaccess nginx rewrite

我已经尝试了两天将.htaccess转换为nginx重写原始文件,如下所示:

# Turn on URL rewriting
RewriteEngine On

RewriteBase //

# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# List of files in subdirectories will not be displayed in the browser
Options -Indexes

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

AddDefaultCharset utf-8
AddCharset UTF-8 .htm .html .txt
AddType "text/html; charset=UTF-8" .htm .html .txt
AddType "text/css; charset=UTF-8" .css
AddType "text/javascript; charset=UTF-8" .js

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

我设法解决了这个问题:

# nginx configuration 
charset utf-8; 
autoindex off; 

location /application {
rewrite ^/(?:application|modules|system)\b.* /index.php/$0 break;
} 
location /modules {
rewrite ^/(?:application|modules|system)\b.* /index.php/$0 break;
}
location /system { 
rewrite ^/(?:application|modules|system)\b.* /index.php/$0 break; 
} 
location / { 
if (!-e $request_filename){ 
rewrite ^(.*)$ /index.php/$0; 
} 
} 
location ~ \.* { 
deny all; 
}

但是当我重新启动nginx时,我得到:[emerg] unknown“0”变量  nginx:配置文件/etc/nginx/nginx.conf测试失败

我不明白为什么会这样。有人请求帮我吗?

1 个答案:

答案 0 :(得分:0)

尝试将$0替换为$uri$request_uri