dz̸apacheºÍnginxµÄrewriteµÄÇø±ð

5年以前  |  阅读数:399 次  |  编程语言:PHP 

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;

}

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例