今天爱分享给大家带来Apache和Nginx规则的对应关系【附表】,希望能够帮助到大家。
| apache的规则 | nginx的规则 |
|---|---|
| RewriteCond | 对应Nginx的if |
| RewriteRule | 对应Nginx的rewrite |
| [R] | 对应Nginx的redirect |
| [P] | 对应Nginx的last |
| [R,L] | 对应Nginx的redirect |
| [P,L] | 对应Nginx的last |
| [PT,L] | 对应Nginx的last |
例如:允许指定的域名访问本站,其他的域名一律转向blog.itblood.com
Apache:
RewriteCond %{HTTP_HOST} !^(.*?)\.aaa\.com$[NC]
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond %{HTTP_HOST}!^192\.168\.0\.(.*?)$
RewriteRule ^/(.*)$ http://www.linuxidc.net[R,L]
Nginx:
if( $host ~* ^(.*)\.aaa\.com$ )
{
set $allowHost '1';
}
if( $host ~* ^localhost )
{
set $allowHost '1';
}
if( $host ~* ^192\.168\.1\.(.*?)$ )
{
set $allowHost '1';
}
if( $allowHost !~ '1' )
{
rewrite ^/(.*)$ http://www.linuxidc.netredirect ;
}
原文链接:https://blog.itblood.com/552.html,转载请注明出处。

![【欧美SLG/汉化/完结】我的可爱表姐2v16.10260完结 AI版【PC+安卓/5.93G/更新】My Cute Roommate 2 [v16.10260 Extra]](/wp-content/uploads/replace/2025/11/02/2adca513cb6558cc588647ef38af898e.webp)