Welcome! Log In Create A New Profile

Advanced

Re: 301 Redirect

Sergey A. Osokin
November 24, 2022 03:52PM
Hi there,

On Wed, Nov 23, 2022 at 08:38:27PM -0500, davidcapital wrote:
> Hello, I would like to know the code to redirect a subdomain to mobile,
> could anyone help me?
>
> ex:RewriteCond %{HTTP_USER_AGENT} "ipod|iphone|ipad|android|palm" [NC]
>
> RewriteRule (.*) http://m.yoursite.com.br/[R=301,L]

It's possible to configure nginx with the map directive [1] with the
$http_user_agent embedded variable [2], something like this (not tested):

map "$http_user_agent" $mobile {
default 0;
"~*ipod" 1;
# define other user agents here
}

server {
...
if ($mobile) {
return 301 http://m.yoursite.com.br;
}
}

References
1. http://nginx.org/en/docs/http/ngx_http_map_module.html#map
2. https://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_

Hope that helps.

--
Sergey A. Osokin
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

301 Redirect

davidcapital November 23, 2022 08:38PM

Re: 301 Redirect

Sergey A. Osokin November 24, 2022 03:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 69
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready