How to write nginx subdirectory 301 redirect
ringa_lee
ringa_lee 2017-06-06 09:54:36
0
2
859

I recently encountered such a problem about the website.
The PC address page is similar to www.abc.com/pc/123/index.html
The corresponding M-side address is m.abc.com/sj/123/index.html
123 This directory is not fixed There are other names, pc and sj are fixed, so there are other such correspondences, such as:
PC www.abc.com/pc/222/index.html
M m.abc.com /sj/222/index.html

You need to make a judgment and jump in nginx here. My original writing method is:

location /pc/ {
    if ($http_user_agent ~* "((Android)|(blackberry)|(googlebot-mobile)|(iemobile)|(ipad)|(iphone)|(opera mobile)|(palmos)|(webos)|(UCBrowser)|(wap)|(Opera Mobi))"){
                    return 301 http://m.abc.com/sj$request_uri;
}

Obviously the above writing method will become a jump corresponding to this:
PC www.abc.com/pc/222/index.html
M m.abc.com/sj/pc/222/ index.html
This is not what I want. How to remove the pc directory from $request_uri?
Please ask God. How to rewrite?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!