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. Technical SEO Issues
    4. Help creating a 301 redirect in my htaccess file

    Help creating a 301 redirect in my htaccess file

    Technical SEO Issues
    4 3 108
    • 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.
    • Felip3
      Felip3 last edited by

      Hi Guys,

      I'm trying to build a 301 file with the file requirements:

      1. It should be visible only for Google and other Search Engine Agents.
      2. It will have a few direct redirects.
      3. A few URL must be dynamic redirect. For example each page the starts with olddomain.com/category and is not in the list of of direct redirects should be redirect for newdomain.com/category

      Here is my start point:

      #301 Starts here

      Set the agents

      RewriteEngine On
      RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
      RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
      RewriteCond %{HTTP_USER_AGENT} Slurp

      Make the direct redirect.

      Redirect 301 /category/sub1 http://www.newdomain.com/category/sub1
      Redirect 301 /category/sub2 http://www.newdomain.com/category/sub2

      Redirect everything else

      Redirect 301 /category/* http://www.newdomain.com/category

      #End of my 301

      Will that work how I want? is there anything wrong?

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

        For the directories I think you need to go down the rewrite route.  This isn't probably functioning correctly but you get the principle.

        RewriteCond %{THE_REQUEST} ^GET\ /category/
        RewriteCond %{REQUEST_URI} !^/category/sub1/
        RewriteCond %{REQUEST_URI} !^/category/sub2/
        RewriteRule ^category/(.*) http://www.newdomain.com/category/$1 [L,R=301]

        RewriteCond %{THE_REQUEST} ^GET\ /category/sub1
        RewriteRule ^category/sub1(.*) http://www.newdomain.com/category/sub1/$1 [L,R=301]

        RewriteCond %{THE_REQUEST} ^GET\ /category/sub2
        RewriteRule ^category/sub2(.*) http://www.newdomain.com/category/sub2/$1 [L,R=301]

        1 Reply Last reply Reply Quote 1
        • ThompsonPaul
          ThompsonPaul last edited by

          Setting redirects to apply only to search crawlers is pretty much their definition of cloaking, Felip3. The site could end up in a world of hurt if/when caught.

          What's the reason for wanting the crawlers to be redirected differently than users? Maybe there's a better way to accomplish what you need in a way that doesn't break their terms of service.

          Paul

          Felip3 1 Reply Last reply Reply Quote 1
          • Felip3
            Felip3 @ThompsonPaul last edited by

            Hi Thompson,

            Thanks for your input, so I'm planning on eventually do the 301 for everyone. I'm re-designing  a big website and not everything is done, but I want users that are looking for the content that I already completed to land in the new site. (because the new site has a much higher conversion rate).

            In other hand I have 30% of my traffic in my old site coming from direct visitors, I dont want those visitors to be send to other URL because it would be confusing. however I want people coming from google to go my new site...

            Do you think I should sacrifice usability, so I don't risk Google to think I'm trying to do some kind of black hat, strategy.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            • 301 redirect syntax for htaccess
              IOHanna
              IOHanna
              1
              3
              6.0k

            • 301 redirects without .htaccess
              NancyVPS
              NancyVPS
              0
              5
              2.0k

            • Creating a CSV file for uploading 301 redirect URL map
              Dan-Lawrence
              Dan-Lawrence
              0
              3
              2.5k

            • 301 Redirect Help
              dhidalgo1
              dhidalgo1
              1
              3
              115

            • Need Help writing 301 redirects in .htaccess file
              Dr-Pete
              Dr-Pete
              0
              5
              1.3k

            • Help needed please with 301 redirects in htaccess file.
              petersommertravels
              petersommertravels
              0
              9
              2.3k

            • 301 redirect .htaccess problem
              sferrino
              sferrino
              0
              4
              709

            • 301 Redirect Help
              hiphound
              hiphound
              0
              3
              891

            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