Home  >  Q&A  >  body text

rewrite - Find the rewriting rules for an nginx personalized domain name

Idea:
http://abc.ccav.com rewrite to http://www.ccav.com/uid/abc
http://abc.ccav.com/article/index/index rewrite to http://www.ccav.com/article/index/index/uid/abc
http://abc.ccav.com/article/index/show/id/1 rewrite to http://www .ccav.com/article/index/show/uid/abc/id/1
http://abc.ccav.com/shop/index/index rewrite to http://www.ccav.com/shop/ index/index/uid/abc
http://abc.ccav.com/shop/index/show/id/1 rewrite to http://www.ccav.com/shop/index/show/uid/abc /id/1
I actually tried it a few times but failed, please give me some advice

phpcn_u1582phpcn_u15822712 days ago723

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 17:25:29

    Solved it myself

    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;
        }
    }
    
    

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:25:29

    This is not rewriting, it should be called a jump, you can do 301, when $host = 'abc.ccav.com', ^/(.*)$ http://www.ccav.com/$1 permanent; Idea That’s it

    reply
    0
  • Cancelreply