What I want to do;

I want mobile users to be redirected to http://m.site.org/mobile-home.

Being redirected to the m.bzaeds.org isn't an issue. I also have this working fine in Apache, but the same .htaccess rule I have in apache doesn't seem to be working in NGINX. I also tried to convert this exact rule using an NGINX translator, but the rule it gave me did not work either.

  RewriteCond %{HTTP_HOST} m.site.org
  RewriteCond %{REQUEST_URI} ^\/?$
  RewriteRule ^(.*)$ mobile-home [L]

What I've done so far;

So, I have NGINX redirecting to m.site.here/mobile-home. Now, we use a Mobile module that detects if the device connected is a mobile device and automatically applies a custom mobile theme. It is detecting with no issues if a device is a mobile device.

However, it fails to load even though the redirection is working and I looked in the error_log and noticed it was failing because /var/www/html/drupal/mobile-home didn't exist -- which, yes, is true. I'm assuming this has something to do with mobile-home actually being a node, because that's what pages are in drupal.

However, no matter how I tried to create the redirect (or return 301), it either was forbidden, infinite redirect loop of doom, or threw me the aforementioned error.

Any ideas?

Now here is a plethora of confusion that I've tried so far;

    location / {
            #if ($http_user_agent ~* '(iPhone|iPod|android|blackberry)') {
    #   rewrite ^/(.*)$ /index.php?q=$1;
            #if ($http_host ~ "m.bzaeds.org"){
            #rewrite ^(.*)$ /mobile-home [L] RewriteCond $request_filename !-f;
    try_files $uri @rewrite;
    #try_files $uri /mobile-home break;

    location @rewrite {
        #index index.php;
    #   if ($http_user_agent ~* ('iPhone|iPod)') {
    #     rewrite ^(.*)$/index.php http://m.bzaeds.org/mobile-home$1 break;
    #   }
        # Some modules enforce no slash (/) at the end of the URL
            # Else this rewrite block wouldn't be needed (GlobalRedirect)
    rewrite ^/(.*)$ /index.php?q=$1;
    #return 301 /mobile-home break;

(And, I've also tried getting rid of location @rewrite and just doing the main rewrite under location / , but I still got many of the same errors. I just had done this statement like this in my non-mobile version, so, mmyes.)

  • Honestly, this question doesn't make a lot of sense to me. Could you simplify this to (a) what you've got and (b) what it should do that it doesn't? – nickgrim Oct 1 '13 at 16:53
  • I basically have nothing. Nothing I've done works. All I could post is what I've tried. I have a Drupal Site, and a page called /mobile-home exists. All I want is when a user on an iPhone or iPad or Android phone connects to the site, I want them to be redirected to the /mobile-home . However, my statements have done that and redirected to m.site.org/mobile-home, but it fails and the error log says /var/www/html/drupal/mobile-home doesn't exist. Which, again, true, and figure this correlates to it being Drupal. – Ethabelle Oct 1 '13 at 16:56
  • 1
    so what i understand: you want mobile-users, who accesses www.site.org, beeing redirected to m.site.org/mobile-home, right? mobile-detetcion is done by UA, right? – that guy from over there Oct 2 '13 at 6:43

So, I didn't do this they way I ultimately wanted to with redirection because no matter what I tried it still wouldn't stop looking in the wrong place. However, I did discover that if you are using the module "Mobile Tools" it gives you the option under "Front Page" to set it to a node, in our case, mobile-home rather than index.

Problem fixed, problem solved, good enough.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.