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. Removing URL Parentheses in HTACCESS

    Removing URL Parentheses in HTACCESS

    Technical SEO Issues
    6 2 1.5k
    • 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.
    • JaredMumford
      JaredMumford last edited by

      Im reworking a website for a client, and their current URLs have parentheses. I'd like to get rid of these, but individual 301 redirects in htaccess is not practical, since the parentheses are located in many URLs.

      Does anyone know an HTACCESS rule that will simply remove URL parantheses as a 301 redirect?

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

        I have 1 or two suggestions. Could you provide an example of the URL? This will allow me to give a more definiive  solution

        JaredMumford 1 Reply Last reply Reply Quote 0
        • JaredMumford
          JaredMumford @Amsplash last edited by

          Hi Merlin  - thank you.

          Here is an example:

          www.domain-name.com/category1/subcategory/product-name-details-(model-number)-length

          needs to change to:

          www.domain-name.com/category1/subcategory/product-name-details-model-number-length

          Any suggestion would be great. Their programmer is having trouble creating a rule.

          Thanks in advance

          Amsplash JaredMumford 2 Replies Last reply Reply Quote 0
          • Amsplash
            Amsplash @JaredMumford last edited by

            Ok,

            having looked at the site I would recommend that the changes are done via server side. I assume the htaccess file is been used to to parse category/subcategory/productname to a controller. Within that controller if the product is found clean the product name with the function below test it against the given url and do a 301 redirect to the cleaned name if they do not match

            function clean_name($string) {    $non_acceptable = '#[^-a-zA-Z0-9 ]#';    $string = preg_replace($non_acceptable, '', $string);    $string = trim($string);     $string = preg_replace('#[-_ ]+#', '-', $string);     return $string;  }

            1 Reply Last reply Reply Quote 0
            • JaredMumford
              JaredMumford @JaredMumford last edited by

              thanks Merlin - Ill have their programmer try this.

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

                I thought I'd come back and re-post the solution in case this shows up in SERPs or anyone other Moz members are looking for this answer (courtesy Noah Wooden of Izoox). HTACCESS:

                <ifmodule mod_rewrite.c="">RewriteEngine On

                # Strip set of opening-closing parenthesis from URL and 301 redirect.
                    RewriteCond %{REQUEST_URI} [()]+
                    RewriteRule ^(.)[(]+([^)])[)]+(.*)$ /$1$2$3 [R=301,L]</ifmodule>

                Remember to put this in the proper 'order' on your htaccess file if you are doing any other redirecting. The code above 301 redirects URLs with parentheses into the exact same URL minus the parentheses.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Removed URLs
                  RossKernez
                  RossKernez
                  0
                  2
                  33

                • After you remove a 301 redirect that Google has processed, will the new URL retain any of the link equity from the old URL?
                  johnwalkersmith
                  johnwalkersmith
                  0
                  3
                  61

                • Removing a URL from Search Results
                  williammarlow
                  williammarlow
                  0
                  3
                  204

                • Removing Redirected URLs from XML Sitemap
                  Travis-W
                  Travis-W
                  0
                  2
                  2.6k

                • .htaccess: Multiple URLs catches filename
                  rasmusbang
                  rasmusbang
                  0
                  2
                  197

                • Speed up the process of removing URLs from Google Index
                  KeriMorgret
                  KeriMorgret
                  0
                  4
                  539

                • Remove a directory using htaccess
                  mediabase
                  mediabase
                  0
                  4
                  2.2k

                • How to handle URL's from removed products?
                  U-Digital
                  U-Digital
                  0
                  5
                  732

                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