Posts Tagged ‘apache rewrite’

apache rewrite转nginx–对大括号(花括号)的支持

在nginx中这样写规则
rewrite [\w]{5,20} /index.php last; 是无法启动的
解决的办法是加上两个双引号
rewrite “[\w]{5,20}” /index.php last; 这样就OK了
应该可以说是完全兼容apache的语法的,只需要改下RewriteRule为Rewrite,后面的
的这样对应改
[R] -> redirect;
[P] -> last;
[R,L] -> redirect;
[P,L] -> last;
[PT,L] -> last;
nginx rewrite中支持4种类型的转向:
跳转型的
redirect:302跳转到rewrite后的地址
permanent:301永久定向到rewrite后的地址,对搜索引擎更友好
代理型的
last:重新将rewrite后的地址在server标签中执行
break:将rewrite后的地址在当前location标签中执行

Read the rest of this entry »

Apache URL rewrite规则

Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言。可基于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式。如果要想用到rewrite模块,必须先安装或加载rewrite模块。方法有两种一种是编译apache的时候就直接安装rewrite模块,别一种是编译apache时以DSO模式安装apache,然后再利用源码和apxs来安装rewrite模块。
基于服务器级的(httpd.conf)有两种方法,一种是在httpd.conf的全局下直接利用RewriteEngine on来打开rewrite功能;另一种是在局部里利用RewriteEngine on来打开rewrite功能,下面将会举例说明,需要注意的是,必须在每个virtualhost里用RewriteEngine on来打开rewrite功能。否则virtualhost里没有RewriteEngine on它里面的规则也不会生效。
基于目录级的(.htaccess),要注意一点那就是必须打开此目录的FollowSymLinks属性且在.htaccess里要声明RewriteEngine on。

Read the rest of this entry »