今天爱分享给大家带来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,转载请注明出处。

![魔纹缠身-强气少女绝不会堕落-V0.20.6 体验版 官方中文版[更新][1.1G] [RPG/中文/动态]](/wp-content/uploads/replace/2025/10/09/ce9f045ca84f0260fef98ecbcfb5fa4a.webp)