rewrite - 求一个nginx个性域名的重写规则
phpcn_u1582
phpcn_u1582 2017-05-16 17:23:29
0
2
722

想法:
http://abc.ccav.com rewrite 到 http://www.ccav.com/uid/abc
http://abc.ccav.com/article/index/index rewrite 到 http://www.ccav.com/article/index/index/uid/abc
http://abc.ccav.com/article/index/show/id/1 rewrite 到 http://www.ccav.com/article/index/show/uid/abc/id/1
http://abc.ccav.com/shop/index/index rewrite 到 http://www.ccav.com/shop/index/index/uid/abc
http://abc.ccav.com/shop/index/show/id/1 rewrite 到 http://www.ccav.com/shop/index/show/uid/abc/id/1
自己实际试了几下,都没成功,求大神指点

phpcn_u1582
phpcn_u1582

全部回复(2)
大家讲道理

自己解决了

server {
    listen 80;
    #rewrite_log on;
    #error_log /datas/logs/ccav_rewrite.log notice;
    server_name *.u.ccav.com;
    location ~ ^/(images|styles|scripts|uploads)/
    {
        proxy_redirect        off;
        proxy_set_header    Host   www.ccav.com;
        proxy_pass      http://127.0.0.1:80;
    }
    location / {
        set $uid default;
        if ( $http_host ~* "^(.*)\.u\.ccav\.com") {
            set $uid ;
        }
        rewrite ^/article/index/show/id/([0-9]+)/?$  /article/index/show/uid/$uid/id/ break;
        rewrite ^/article/index/index/?$  /article/index/index/uid/$uid break;
        rewrite ^/article/index/category/cid/([0-9]+)/?$  /article/index/category/uid/$uid/cid/ break;
        proxy_pass http://www.ccav.com;
    }
}

Ty80

这是不重写,应该叫跳转,可以做301,当$host = 'abc.ccav.com' 时,^/(.*)$ http://www.ccav.com/$1 permanent; 思路就是这样的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!