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. Redirecting from _ to - ?

    Redirecting from _ to - ?

    Intermediate & Advanced SEO
    2 2 92
    • 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.
    • FCRMediaLietuva
      FCRMediaLietuva last edited by

      hi everyone,

      I need your help! ๐Ÿ™‚

      What's the best way to redirect a lot of urls from sign _ to sign - ?

      We changed our e-shop CMS and we don't use that _ anymore.

      We have more than 100.000 URLs and you can imagine that we don't to do by hand.

      Any chance of doing it with .htaccess easily?

      Thanks!

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

        Yes, you can use the following two rules, in this exact order, in your .htaccess file. I'm assuming you've got mod_rewrite on.

        RewriteRule ^([^]*)([^]*.) $1-$2 [N]
        RewriteRule ^([^_]
        )([^]*)$ /$1-$2 [L,R=301]

        The first bracketed group in each rule -- ([^_]*) -- matches every group of characters that isn't an underscore. The first rule rewrites every underscore in the URL to a hyphen, until there's only one underscore left. At this point, control passes to the second rule, which replaces that final underscore with a hyphen, and 301 redirects to that page.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        • Would You Redirect a Page if the Parent Page was Redirected?
          Nozzle
          Nozzle
          0
          4
          92

        • Should I do a redirect
          0
          1
          33

        • Redirect Plugin: Redirecting or Rewriting?
          HashtagHustler
          HashtagHustler
          0
          3
          230

        • How to redirect an url in .htaccess when "redirect 301" doesnt work
          WilliamKammer
          WilliamKammer
          0
          5
          173

        • Redirecting a redirect - thoughts?
          MikeRoberts
          MikeRoberts
          0
          2
          165

        • How to conduct catch 301 redirects & have the separate 301 redirects for the key pages
          BenRWoodard
          BenRWoodard
          0
          2
          288

        • Duplicate titles but redirecting anyway (without redirects set up!!!)
          JGar-28032
          JGar-28032
          1
          2
          348

        • Multiple 301 redirects considered a redirection chain?
          jmueller
          jmueller
          1
          16
          5.0k

        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