從Apache遷移到Nginx時,.htaccess文件中的某些規則必須'轉換'爲Nginx的配置文件。 一個問題,我似乎無法來解決,一個例子是解釋最簡單的方法:是否存在與Apaches的{ENV:REDIRECT_STATUS}等效的Nginx環境變量?
請求http://www.domain.com/nginx
在內部被阿帕奇改寫爲index.php?option=com_content&view=article&id=145
現在我想阻止請求定向到index.php?option=com_content
所以頁面僅可通過http://www.domain.com/nginx
以避免重複的內容。在Apache中,這是通過使用這些.htaccess規則實現的:
# Check if it's the first pass to prevent a loop. In case of first pass, the environment variable contains nothing
# If http://www.domain.com/nginx already internally has been rewritten to index.php?option=com_content&view=article&id=145 {ENV:REDIRECT_STATUS} contains '200' and the request is allowed to be processed
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Check if the query string contains requests for the page
RewriteCond %{QUERY_STRING} ^index.php?option=com_content&view=article&id=145 [NC]
# If conditions apply, reject request
RewriteRule .* 404 [L]
在Nginx中,是否有這樣一個環境變量,我可以使用? 或者我應該以完全不同的方式來解決這個問題?
編輯1: 在現實生活中,它不僅僅是一個頁面,而是一個動態的Joomla網站,有很多頁面。我測試其中工程以上,但其意圖是阻止在index.php的所有請求option_content &視圖=文章& ID = *
編輯2: 這是工作NGINX配置文件:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/domainname;
index index.php index.html index.htm;
server_name domainname.com;
server_name localhost;
location/{
try_files $uri $uri/ /index.php?$args;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
## give 404 header & redirect to custom errorpage without changing URL ##
error_page 404 = /404_custom.php; #global error page, script handles header
error_page 500 502 503 504 /50x.html;
location =/index.php {
set $arg_set "${arg_option}___${arg_view}___${arg_id}";
if ($arg_set ~* "^(((\w|-)+?)___){2}((\w|-)+?)$") {
return 404;
}
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
有指令'內部'http://nginx.org/r/internal –