Apache Access RewriteRule重写URL转 Nginx rewrite无效

javaluo 发布于 2011/06/24 13:28
阅读 2K+
收藏 0

Apache URL规则

RewriteEngine On
RewriteBase /


RewriteRule ^([a-z]+)/p-([0-9]+)\.htm$ /HBclass\.php\?lanmu=$1&p=$2
RewriteRule ^([a-z]+)/([a-z]+)\.htm$ /HBclass\.php\?lanmu=$1&p=$2
RewriteRule ^([a-z]+)/$ /HBclass\.php\?lanmu=$1&p=$2
RewriteRule ^([a-z]+)$ /HBclass\.php\?lanmu=$1&p=$2
RewriteRule ^([a-z]+)/d-([0-9a-z\-]+)\.htm$ /article\.php\?lanmu=$1&id=$2
RewriteRule ^([a-z]+)/a-([0-9]+)\.htm$ /all\.php\?lanmu=$1&a=$2
RewriteRule ^([a-z]+)/tag-(.*)-([0-9]+)$ /tag\.php\?lanmu=$1&tag=$2&page=$3
RewriteRule ^([a-z]+)/tag-(.*)\.htm$ /tag\.php\?lanmu=$1&tag=$2
RewriteRule ^go/act/(.*)/([0-9a-z\-]+)\.php$  /zhuanti\.php\?cat1=$1&cat=$2         [L]
RewriteRule ^index\.htm /index\.php

转成 Nginx 规则如下:

server {
        listen       80;
        server_name  localhost;
        root   /usr/nginx/html;
        index  index.html index.htm index.php;
        location /{
     rewrite  ^([a-z]+)/p-([0-9]+)\.htm$ /HBclass\.php\?lanmu=$1&p=$2;
     rewrite  ^([a-z]+)/([a-z]+)\.htm$ /HBclass\.php\?lanmu=$1&p=$2;
     rewrite  ^([a-z]+)/$ /HBclass\.php\?lanmu=$1&p=$2;
     rewrite  ^([a-z]+)$ /HBclass\.php\?lanmu=$1&p=$2;
     rewrite  ^([a-z]+)/d-([0-9a-z\-]+)\.htm$ /article\.php\?lanmu=$1&id=$2;
     rewrite  ^([a-z]+)/a-([0-9]+)\.htm$ /all\.php\?lanmu=$1&a=$2;
     rewrite  ^([a-z]+)/tag-(.*)-([0-9]+)$ /tag\.php\?lanmu=$1&tag=$2&page=$3;
     rewrite  ^([a-z]+)/tag-(.*)\.htm$ /tag\.php\?lanmu=$1&tag=$2;
     rewrite  ^go/act/(.*)/([0-9a-z\-]+)\.php$  /zhuanti\.php\?cat1=$1&cat=$2;
     rewrite  ^index\.htm /index\.php;
    }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location /nginx_status {
            stub_status on;
            access_log   off;
        }
    }

访问路径http://localhost/man/index.htm 找不到路径,不知道哪里写错了,在APACHE下是可以的。

加载中
返回顶部
顶部