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. .htaccess yikes!

    .htaccess yikes!

    Technical SEO Issues
    8 4 79
    • 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.
    • MrPenguin
      MrPenguin last edited by

      Hi guys,

      Having a bit of trouble getting a htaccess redirect working. It's very easy but I am making a small typo somewhere!

      I want to redirect about 400 product pages located at;

      http://domain.com/product/product-name

      to

      http://domain.com/product-name

      ..basically just dropping /product/

      Any help would be appreciated as my errors in Moz are all over the place!

      1 Reply Last reply Reply Quote 0
      • Ray-pp
        Ray-pp last edited by

        Hello MrPenguin,

        Your code should look similar to this:

        Redirect 301 /product/product-name http://domain.com/product-name

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

          I'm sure you don't want to rewrite all the pages 1 at a time, try the following to rewrite the entire folder.

          Options +FollowSymLinks
          RewriteEngine on
          RewriteCond %{REQUEST_URI} !(.)product
          RewriteRule ^(.
          )$ product/$1 [L]

          1 Reply Last reply Reply Quote 0
          • Matt-Williamson
            Matt-Williamson last edited by

            You could use the following RedirectMatch directive in your htaccess file obviously swapping in your actual domain -

            RedirectMatch 301 ^/product/(.*)$ http://www.domain.com/$1 
            
            
            MrPenguin 1 Reply Last reply Reply Quote 0
            • MrPenguin
              MrPenguin @Matt-Williamson last edited by

              Thanks for this, appears to work fine!

              Is it ok sitting at the end?

              BEGIN WordPress

              <ifmodule mod_rewrite.c="">RewriteEngine On
              RewriteBase /
              RewriteRule ^index.php$ - [L]
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule . /index.php [L]
              RedirectMatch 301 ^/product/(.*)$ http://cdkeyprices.com/$1</ifmodule>

              END WordPress

              #php_flag display_startup_errors on
              #php_flag display_errors on
              #php_flag html_errors on
              #php_value docref_root 0
              #php_value docref_ext 0

              Matt-Williamson 1 Reply Last reply Reply Quote 0
              • Matt-Williamson
                Matt-Williamson @MrPenguin last edited by

                mod_rewrite and RedirectMatch are two different ways of doing a 301 redirect - both are fine. You can have both inside a htaccess file, however you may want to place the RedirectMatch directive outside of the call for the mod_rewrite module so after

                MrPenguin 1 Reply Last reply Reply Quote 0
                • MrPenguin
                  MrPenguin @Matt-Williamson last edited by

                  Looks the good, thanks for all your help.

                  Matt-Williamson 1 Reply Last reply Reply Quote 0
                  • Matt-Williamson
                    Matt-Williamson @MrPenguin last edited by

                    No problem - that's what this community is all about 😄

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    • Set Up htaccess File
                      GFD_Chris
                      GFD_Chris
                      0
                      2
                      48

                    • .htaccess Question
                      seanginnaw
                      seanginnaw
                      0
                      2
                      63

                    • .htaccess code
                      KevinBudzynski
                      KevinBudzynski
                      0
                      8
                      68

                    • Htaccess redirects
                      Tom-Anthony
                      Tom-Anthony
                      0
                      3
                      220

                    • .htaccess redirect question
                      David-Kley
                      David-Kley
                      0
                      4
                      541

                    • Htaccess query
                      ShaMenz
                      ShaMenz
                      0
                      6
                      469

                    • Htaccess rewrites
                      AndrewAkesson
                      AndrewAkesson
                      0
                      7
                      705

                    • .htaccess help please
                      Dr-Pete
                      Dr-Pete
                      0
                      3
                      461

                    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