I have example.com and m.example.com which both rel=canonical and rel=alternate to each other. On my mobile site I have a "desktop site" link that links to example.com?mobileOut that opts out of the mobile redirect. The issue is example.com/?mobileOut is getting indexed with the ?mobileOut param in the url. Can I nofollow the "desktop site" link and be safe?

  • Can I assume that the reason you link to mysite.com/?mobileOut is because mysite.com is redirecting mobile users to m.mysite.com? – nathangiesbrecht Mar 3 '15 at 18:07
  • 1
    Also, when you say that you have rel=canonical and rel=alternate "pointing to each other", you mean that you have <link rel="canonical" href="mysite.com" /> on moth m.mysite.com and mysite.com, correct? If you have the canonical pointing to two different URLs, that could be causing problems. – nathangiesbrecht Mar 3 '15 at 18:09
  • My rel=canonical and alternate are correct per Google's guidelines. To answer your first question, you are correct, mysite.com will redirect mobile users to m.mysite.com unless overridden by the mobileOut param. How would you go about doing this? – Trey Copeland Mar 3 '15 at 19:44
  • What's the canonical on the homepage if you go to example.com/?mobileOut is the canonical=example.com or is it example.com/?mobileOut ? Also where are you checking the browser for mobile/non-mobile? Is it Javascript, PHP, in .htaccess? – nathangiesbrecht Mar 3 '15 at 20:53
  • The canonical on the homepage of mysite.com/?mobileOut is just mysite.com. I am checking for user agent in the .htaccess and doing a redirect from there. – Trey Copeland Mar 3 '15 at 20:57

Your best bet here is to do a 301 redirection.

On your mobile site, you must have link code formatted like this:

<a href="example.com/?mobileOut">Desktop site</a>

First change all those to:

<a href="http://example.com">Desktop site</a>

Because when someone access just the domain name (without parameters), they should expect the website to load.

Once you done that, modify your sitemaps so that links that look like:


get changed to:


Then finally, to make google finally understand things and to add additional safety, you need to make to create a redirection to the main site.

In an .htaccess file (create it if it doesn't exist) in the website document root folder, you can add the following:

RewriteEngine On
RewriteRule ^(\?)?mobileOut$ http://example.com [R=301,L]

Or if what is handling the parameters is a PHP script, you could add the following to the top of it:

    if ($qs=="mobileOut" || $qs=="?mobileOut"){
        header("HTTP/1.1 301 Moved Permanently",true);
        header("Location: http://example.com",true);
 .... rest of your PHP code here ....

Both pieces of code should cause anyone typing the site with the parameter to get redirected to the main site and when google recognizes this, they will refuse to index the page with the parameter, but instead index the domain name only.

I had to change the domain in my answer to example.com because this site doesn't like me to use mysite as the domain.

| improve this answer | |
  • I'm guessing the reason that this won't work, is that he has logic at example.com to redirect mobile users to m.example.com and your solution would then result in an infinite loop for mobile users. – nathangiesbrecht Mar 3 '15 at 18:06
  • Nathan is correct here. This would not work in my scenario. – Trey Copeland Mar 3 '15 at 19:45
  • I don't see exactly how there is logic shown to redirect mobile users to m.example.com from example.com? If it is because of the rel attributes then they should be removed for now while debugging the problem. I think Web browsers would recognize a 301 more than a rel tag. I bet its the rel tags that are throwing google off and google is internally treating the page with a rel tag as if it was a 301 page to another page which contributes to a loop Nathan claims to exist? – Mike -- No longer here Mar 4 '15 at 4:56

There is a feature in Google Webmaster Tools that will solve this problem for Google. Navigate to:

  • Crawl
  • URL Parameters
  • Add Parameter

Put in "mobileOut" then "Doesn't affect the page content".

Save this change and Google will no longer crawl and index the mobileOut parameter. Instead it will favor the version of the URL without the parameter.

| improve this answer | |

In your htaccess, you could add a condition to your rewrite to check if the referer is from your own site, then skip the mobile-user-agent check and proceed as normal. This way, someone lands on your page, gets redirected to m.example.com, clicks the Desktop link, your .htaccess file then, instead of redirecting back to m.example.com see's that the user was refered from your own site, thus skips the mobile check. This will also allow users to surf around your site without getting redirected back to m.example.com, but the next time they return, they'll be redirected to mobile as you'd expect. If you want the change to be kept for them accross sessions, you'd need to utilize a cookie.

An example re-write would be:

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone" [NC]
RewriteCond %{HTTP_REFERER} !^http://m.example.com/.* [NC]
RewriteRule (.*) http://m.example.com/$1 [R=302,L]

Which basically just says "if it's a mobile user-agent, and they were not referred here by my mobile site, then redirect them to my mobile site.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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