1. Nginx Rewrite¹aeÔoÏa¹ØÖ¸Ái
Nginx Rewrite¹aeÔoÏa¹ØÖ¸ÁiÓÐif¡¢rewrite¡¢set¡¢return¡¢breakµÈ£¬ÆaÖÐrewriteÊÇ×i¹Ø¼uµÄÖ¸Ái¡£Ò»¸o¼oµ¥µÄNginx Rewrite¹aeÔoÓi*¨ÈçÏÂ:
rewrite ^/b/(.*)\.html /play.php?video=$1 break;
Èç¹u¼ÓÉÏifÓi¾a£¬Ê¾ÀýÈçÏ£º
if (!-f $request_filename)
{ rewrite ^/img/(.*)$ /site/$host/images/$1 last; }
2. NginxÓeApacheµÄRewrite¹aeÔoʵÀý¶Ô±È
¼oµ¥µÄNginxºÍApache ÖØд¹aeÔoÇø±ð²»´o£¬»u±¾ÉÏÄܹ»ÍeÈ«¼aeÈÝ¡£
Apache Rewrite ¹aeÔo£º
RewriteRule ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 [L]
RewriteRule ^/ceshi/$ /zl/ceshi.php [L]
RewriteRule ^/(mianshi)([a-zA-Z]+)/$ /zl/index.php?name=$1$2 [L] RewriteRule ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 [L]
Nginx Rewrite ¹aeÔo£º
rewrite ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 last;
rewrite ^/ceshi/$ /zl/ceshi.php last;
rewrite ^/(mianshi)([a-zA-Z]+)/$ /zl/index.php?name=$1$2 last;
rewrite ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 last;
²»ÄÑ*¢ÏÖApacheµÄRewrite¹aeÔo¸ÄΪNginxµÄRewrite¹aeÔoͦ¼oµ¥µÄ£¬Èç¹u¸ÄÍe¹aeÔo£¬Ê¹ÓÃ"nginx -t"ÃuÁi¼i²e*¢ÏÖnginx.confÅaÖÃÎļþÓÐÓi*¨´iÎo£¬ÄÇô¿ÉÒÔ³¢ÊÔ¸øÌo¼þ¼ÓÉÏÒýºÅ¡£ÀýÈçһϵÄNginx Rewrite¹aeÔo»a±¨Ói*¨´iÎo£º
rewrite ^/([0-9]{5}).html$ /x.jsp?id=$1 last;¼ÓÉÏÒýºÅ¾ÍÕýÈ*ÁË£º
rewrite ¡°^/([0-9]{5}).html$¡± /x.jsp?id=$1 last;
ApacheÓeNginxµÄRewrite¹aeÔoÔÚURLÌøתʱÓÐϸ΢µÄÇø±ð£º
Apache Rewrite ¹aeÔo£º
RewriteRule ^/html/tagindex/([a-zA-Z]+)/.*$ /$1/ [R=301,L]
Nginx Rewrite ¹aeÔo£º
rewrite ^/html/tagindex/([a-zA-Z]+)/.*$ http://$host/$1/ permanent;
ÒÔÉÏʾÀýÖУ¬ÎÒÃÇ×¢Òaµ½£¬Nginx Rewrite ¹aeÔoµÄÖû»´®ÖÐÔo¼ÓÁË¡°http://$host¡±£¬ÕaÊÇÔÚNginxÖÐÒªÇoµÄ¡£
ÁiÍa£¬ApacheÓeNginxµÄRewrite¹aeÔoÔÚ±aÁ¿Ãu³Æ*½ÃaeÒ²ÓÐÇø±ð£¬ÀýÈ磺
Apache Rewrite ¹aeÔo£º
RewriteRule ^/user/login/$ /user/login.php?login=1&forward;=http://%{HTTP_HOST} [L]
Nginx Rewrite ¹aeÔo£º
rewrite ^/user/login/$ /user/login.php?login=1&forward;=http://$host last;
ApacheÓeNginx Rewrite ¹aeÔoµÄÒ»Ð(C)¹¦ÄÜÏaͬ»oÀaËƵÄÖ¸Ái¡¢±e¼Ç¶ÔÓ¦¹Øϵ£º
ApacheµÄRewriteCondÖ¸Ái¶ÔÓ¦NginxµÄifÖ¸Ái£»
ApacheµÄRewriteRuleÖ¸Ái¶ÔÓ¦NginxµÄrewriteÖ¸Ái£»
ApacheµÄ[R]±e¼Ç¶ÔÓ¦NginxµÄredirect±e¼Ç£»
ApacheµÄ[P]±e¼Ç¶ÔÓ¦NginxµÄlast±e¼Ç£»
ApacheµÄ[R,L]±e¼Ç¶ÔÓ¦NginxµÄredirect±e¼Ç£»
ApacheµÄ[P,L]±e¼Ç¶ÔÓ¦NginxµÄlast±e¼Ç£»
ApacheµÄ[PT,L]±e¼Ç¶ÔÓ¦NginxµÄlast±e¼Ç£»
ÔÊÐiÖ¸¶¨µÄÓoÃu*ÃÎʱ¾Õ¾£¬ÆaËuÓoÃuÒ»ÂÉÌøתµ½http://www.aaa.com£º
Apache Rewrite ¹aeÔo£º
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$
RewriteCond %{HTTP_HOST} !^qita\.domain\.com$ RewriteCond %{DOCUMENT_ROOT}/market/%1/index.htm -f
RewriteRule ^/wu/$ /market/%1/index.htm [L]
NginxµÄifÖ¸Ái²»Ö§³ÖǶÌ×£¬Ò²²»Ö§³ÖAND¡¢ORµÈ¶aÌo¼þÆ¥Åa£¬Ïa±ÈÓÚApacheµÄRewriteCond£¬ÏÔµÃÂe³Ò»Ð(C)£¬µ«ÊÇ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÏÂÒ»Ò³µÄNginxÅaÖÃд¨À´ÊµÏÖÕa¸oʾÀý£º
Nginx Rewrite ¹aeÔo£º
if ($host ~ ^(.?)\.domain\.com$)
{
set $var_wupin_city $1;
set $var_wupin ¡®1¡a;
}
if ($host ~* ^qita\.domain\.com$)
{
set $var_wupin ¡®0¡a;
}
if (!-f $document_root/market/$var_wupin_city/index.htm)
{
set $var_wupin ¡®0¡a;
}
if($var_wupin ~ ¡®1¡a)
{
rewrite ^/wu/$ /market/$var_wupin_city/index.htm last;
}