The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Intermediate & Advanced SEO
    4. Code to Redirect Mobile Subdomain to Desktop Site

    Code to Redirect Mobile Subdomain to Desktop Site

    Intermediate & Advanced SEO
    3 1 480
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kernmedia
      kernmedia last edited by

      Hi Everyone,

      My client is switching from a mobile subdomain to a responsive site. All URLs are the same on mobile subdomain vs desktop so we just need a wildcard rule to redirect m. to www.

      Anyone have this wildcard redirect code for an .htaccess file?

      Much appreciated!

      Dan

      1 Reply Last reply Reply Quote 0
      • kernmedia
        kernmedia last edited by

        I have some code that I think will work. Would appreciate peer review 🙂

        RewriteCond %{HTTP_HOST} ^m.domain.com
        RewriteRule ^(.*) http://www.domain.com/$1 [R=301]

        I'd like to also avoid redirecting the /robots.txt file and /sitemap.xml file on the mobile subdomain, since I want Google to crawl the sitemap to facilitate faster processing of the redirects. If the code above is correct, how would I add this line of code (below) into the 2nd line of code above?

        RewriteRule ^((?!.?.xml|.?.txt|.?\GoogleVerificationFile.html).).* http://www.domain.com [R=301]

        1 Reply Last reply Reply Quote 0
        • kernmedia
          kernmedia last edited by

          Well, I worked with the developer that contracts with this client and here's what he put in the .htaccess file (domain replaced with "domain"). It did the trick.

          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^m.domain.com
          RewriteCond %{REQUEST_URI} !^/sitemap.xml$
          RewriteCond %{REQUEST_URI} !^/robots.txt$
          RewriteRule ^(.*) http://www.domain.com/$1 [R=301]

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          • Redirecting old mobile site
            CleverPhD
            CleverPhD
            0
            3
            441

          • When Mobile and Desktop sites have the same page URLs, how should I handle the 'View Desktop Site' link on a mobile site to ensure a smooth crawl?
            DirkC
            DirkC
            0
            3
            1.4k

          • Redirecting Pages from site A to site B
            gazzerman1
            gazzerman1
            0
            6
            100

          • Redirection strategy for mobile site
            0
            1
            303

          • 301 or 302 Redirects to Mobile Site
            BrianJGomez
            BrianJGomez
            0
            2
            2.2k

          • It appears that Googlebot Mobile will look for mobile redirects from the desktop site, but still use the SEO from the desktop site.
            BenRWoodard
            BenRWoodard
            0
            3
            414

          • Redirection to mobile site
            Sangeeta
            Sangeeta
            0
            2
            318

          • Mobile subdomain recommendations - Mobile SEO
            Hexpress
            Hexpress
            0
            3
            1.4k

          Get started with Moz Pro!

          Unlock the power of advanced SEO tools and data-driven insights.

          Start my free trial
          Products
          • Moz Pro
          • Moz Local
          • Moz API
          • Moz Data
          • STAT
          • Product Updates
          Moz Solutions
          • SMB Solutions
          • Agency Solutions
          • Enterprise Solutions
          • Digital Marketers
          Free SEO Tools
          • Domain Authority Checker
          • Link Explorer
          • Keyword Explorer
          • Competitive Research
          • Brand Authority Checker
          • Local Citation Checker
          • MozBar Extension
          • MozCast
          Resources
          • Blog
          • SEO Learning Center
          • Help Hub
          • Beginner's Guide to SEO
          • How-to Guides
          • Moz Academy
          • API Docs
          About Moz
          • About
          • Team
          • Careers
          • Contact
          Why Moz
          • Case Studies
          • Testimonials
          Get Involved
          • Become an Affiliate
          • MozCon
          • Webinars
          • Practical Marketer Series
          • MozPod
          Connect with us

          Contact the Help team

          Join our newsletter
          Moz logo
          © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
          • Accessibility
          • Terms of Use
          • Privacy