0
votes

Hi i want to redirect my mobile users from desktop site. The mobile server is based on nginx and i am adding the rewrite rules: i have to add 50 rules and dont know any short cuts.. but the problem is the rule is not working with suffix. for example in my desktop site i have

http://www.example.com/watch/tv-commercial/aci-aerosol-hd/ http://www.example.com/category/tv-commercial/

http://www.example.com/category/music-video/

http://www.example.com/watch/music-video/aji-e-boshonte/

and i want to redirect

http://www.example.com/watch/tv-commercial/

this group to http://m.example.com/funny-clips

and this group to

http://www.example.com/category/music-video/

http://m.bongobd.com/full-movie-natok

if i write

location = /watch/tv-commercial/ {
   return 301 /funny-clips;
}

it works but if it has "aji-e-boshonte"

its not working.

can anyone help? also I have multiple incoming rule to redirect one single route. for example/ tv/movie/comedy(with slug) to /funny-clips do i need to write every time the rule?

1

1 Answers

1
votes

The location = looks for an exact match. You need to use a prefix location or a regex location. For example, to rewrite /watch/tv-commercial/path/to/file to http://m.example.com/funny-clips/path/to/file you might use:

location ~* ^/watch/tv-commercial/(.*)$ {
  return $scheme://m.example.com/funny-clips/$1$is_args$query_string;
}

See this document and this document for details.