NGINX重定向改为apache重定向例子
NGINX重定向规则
代码如下 | 复制代码 |
rewrite ^/index.(html|htm)$ /index.$1 last; rewrite ^/index_(hot|new)(_(\d+))?.html$ /index.php?ac=index&st=$1&page=$3 last; rewrite ^/index_(\d+).html$ /index.php?ac=index&page=$1 last; rewrite ^/([a-zA-Z]+)_(new|hot)(_(\d+))?.html$ /index.php?ac=$1&st=$2&tid=$4 last; rewrite ^/([a-zA-Z]+)_(new|hot)_(\d+)_(\d+).html$ /index.php?ac=$1&st=$2&tid=$3&page=$4 last; rewrite ^/([a-zA-Z]+)_(\d+)_(\d+).html$ /index.php?ac=$1&tid=$2&page=$3 last; rewrite ^/([a-zA-Z]+)(_(\d+))?.html$ /index.php?ac=$1&tid=$3 last; |
改成apache重定向之后
代码如下 | 复制代码 |
RewriteEngine On RewriteRule ^/index.(html|htm)$ http://www.xxx.com/index.$1 [R=301] RewriteRule ^/index_(hot|new)(_(\d+))?.html$ http://www.xxx.com/index.php?ac=index&st=$1&page=$3 [R=301] RewriteRule ^/index_(\d+).html$ http://www.xxx.com/index.php?ac=index&page=$1 [R=301] RewriteRule ^/([a-zA-Z]+)_(new|hot)(_(\d+))?.html$ http://www.xxx.com/index.php?ac=$1&st=$2&tid=$4 [R=301] RewriteRule ^/([a-zA-Z]+)_(new|hot)_(\d+)_(\d+).html$ http://www.xxx.com/index.php?ac=$1&st=$2&tid=$3&page=$4 [R=301] RewriteRule ^/([a-zA-Z]+)_(\d+)_(\d+).html$ http://www.xxx.com/index.php?ac=$1&tid=$2&page=$3 [R=301] RewriteRule ^/([a-zA-Z]+)(_(\d+))?.html$ http://www.xxx.com/index.php?ac=$1&tid=$3 [R=301] |
pache转换 nginx可以使用的规则:
代码如下 | 复制代码 |
RewriteEngine On RewriteRule ^/([a-z]+)/p_([0-9]+)\.html$ /list\.php\?id=$1 |
以上为apache的伪静态规则。下面为转换后的nginx规则:
代码如下 | 复制代码 |
rewrite ^/([a-z]+)/p_([0-9]+)\.html$ /list.php?id=$1 last; |
apache后则不能直接使用点和问号,所以将/list\.php\?id=$1中的"\"去掉,即:/list.php?id=$1
将RewriteRule 换为 rewrite,并在在每条规则后加上”last;“
时间: 2024-11-08 21:28:55