Redirect Mobile Users to m.domain.com

Hi all,

I have a wordpress website http://domain.com. I have created a mobile
version of it and put in “m” folder of that domain. I want all my mobile
users to be redirected to http://m.domain.com where http://m.domain.com
will be using a mobile version of the website located in “m” folder. By
using the below rewrite rules, it does redirect to http://m.domain.com
but it does not display any website from the “m” folder. ( Please help:


server {
server_name domain.com www.domain.com;
access_log /home/nginx/domains/domain.com/log/access.log combined
buffer=32k;
error_log /home/nginx/domains/domain.com/log/error.log;
root /home/nginx/domains/domain.com/public;

try_files $uri $uri/ /index.php;

location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
}

location ^~ /m/index.html {
rewrite ^/m/(.*) http://m.domain.com/$1 permanent;
}

Directives to send expires headers and turn off 404 error logging.

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
}

include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;

}

On Tue, Aug 7, 2012 at 4:22 AM, yaronycity [email protected] wrote:

server {
try_files $uri $uri/ /index.php?$args;
}

    location ^~ /m/index.html {
rewrite ^/m/(.*) http://m.domain.com/$1 permanent;

}

Should be just ^~ /m/ { … }

Also maybe add the server block which handles the m. domain… server
{ server_name m.domain.com; root /some/where/m; … }

On Tue, Aug 7, 2012 at 4:45 AM, yaronycity [email protected] wrote:

I have changed it this, and it still does not work:(

server {
server_name domain.com www.domain.com;
root /home/nginx/domains/domain.com/public;

server_name m.domain.com www.m.domain.com;
root /home/nginx/domains/domain.com/public/m;

Add as separate server { … }, not merged into one.

I have changed it this, and it still does not work:(

server {
server_name domain.com www.domain.com;
root /home/nginx/domains/domain.com/public;

server_name m.domain.com www.m.domain.com;
root /home/nginx/domains/domain.com/public/m;

try_files $uri $uri/ /index.php;

location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$args;
}

location ^~ /m/ {
rewrite ^/m/(.*) http://m.domain.com/$1 permanent;
}

Directives to send expires headers and turn off 404 error logging.

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
}

include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;

}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,229364,229367#msg-229367

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs