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. On-Page / Site Optimization
    4. Htaccess redirect, from /year/month to /blog

    Htaccess redirect, from /year/month to /blog

    On-Page / Site Optimization
    3 3 338
    • 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.
    • opiates
      opiates last edited by

      I am trying to make some redirects so we don't lose that SEO juice.

      I am trying to move our blog structure from:
      http://www.domain.com/2015/09/title-of-blog

      to:
      http://www.domain.com/blog/title-of-blog

      I need to do redirects in htaccess from the old structure to the new structure but I can't seem to get it working properly. Here is what I have thus far.

      <code>RewriteEngine on
      RewriteBase /
      RewriteRule ^(.0-9)\/^(.0-9)\$ $1/ [R=301,L]</code>
      

      Any suggestions?

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

        Correct code should be:

        RewriteEngine On
        RewriteBase /
        RewriteRule ^[0-9]+/[0-9]+/[0-9]+/(.*)$ blog/$1 [R=301,L]

        sergeystefoglo 1 Reply Last reply Reply Quote 2
        • sergeystefoglo
          sergeystefoglo @Mobilio last edited by

          This is the right answer minus a few excess characters.

          If the blog structure is domain.com/2015/09/title-of-blog then the correct code would be as follows:

          RewriteEngine On
          RewriteBase /
          RewriteRule ^[0-9]+/[0-9]+/(.*)$ blog/$1 [R=301,L]

          This will result in: domain.com/blog/title-of-blog.

          In other words, Peter you had it right but you just had a few extra characters (you assumed the specific day was also included in the URL structure). Yours would work perfectly if the URL structure was domain.com/2015/09/02/title-of-blog 🙂

          Also, if anyone ever wants to test your rewrite rules this is a great tool. http://htaccess.mwl.be/.

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          • What is the best way to block http://www.site.com/members/...
            Taiger
            Taiger
            0
            3
            136

          • https://www.freedomltd.com/stag-weekend/
            henandstag
            henandstag
            0
            3
            109

          • My home page URL http://seadwellers.com/ redirects to http://www.seadwellers.com/. Is this a problem?
            TheeDigital
            TheeDigital
            0
            3
            100

          • Moving/deleting blog
            bhsiao
            bhsiao
            0
            4
            58

          • Which is best for the website? Example blog that starts blog.domain.com or domain.com/blog? Thanks!
            JonathanLeplang
            JonathanLeplang
            0
            6
            1.3k

          • Blog.mysite.com or mysite.com/blog?
            creybot
            creybot
            0
            5
            912

          • How do I do a 301 Redirect in IIS 7 from http://www.freightmonster.com/index.html to http://freightmonster.com/index.html when I don't have a physical page to redirect?
            EricaMcGillivray
            EricaMcGillivray
            0
            4
            1.0k

          • How do you create a 301 redirect for www.mysite..com/index.html in htaccess.
            davebrown1975
            davebrown1975
            0
            4
            738

          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