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. URL Rewriting Best Practices

    URL Rewriting Best Practices

    Intermediate & Advanced SEO
    12 2 2.9k
    • 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.
    • DmitriiK
      DmitriiK last edited by

      Hi there.

      Well, as for best practices - you got it covered - remove/substitute underscores, remove redundant directories, make urls readable and understandable by users, implement redirects for pages, which are being renamed.

      As for removing extensions from files - i'm not sure it has any effect on SEO or user experience at all. But no, you don't have to create new format pages. Basically what mod_rewrite does is when somebody requests a page, server says "I gonna server you this file with this name, because you sent me this specific request". Just be aware that there is no way to access both original url and rewritten url at the same time, since it would create duplicate issues.

      As for rankings affect - as long as all redirects are done properly and urls are targeting the keywords on the page - you should be fine.

      TheDude 1 Reply Last reply Reply Quote 1
      • TheDude
        TheDude @DmitriiK last edited by

        Thanks for the response Dmitrii!

        Thanks for for confirming that I don't need to update the webpage file names.

        Do you know if redirecting the old directories to the new ones (using the the rewrite below) is all I need to do regarding redirects? In other words, when redirecting directories using the rewrite below is there any need to redirect the old URL format (small_blue_widget.htm) to the new (small-blue-widget)? My understanding is no, all I need to do is redirect the directories; but please share your knowledge.Thanks in advance!

        <code>RewriteRule ^old/(.*)$ /new/$1 [L,R=301]</code> 
        
        DmitriiK 1 Reply Last reply Reply Quote 0
        • DmitriiK
          DmitriiK @TheDude last edited by

          the rule you wrote wont work.

          What it will do is redirect this: _domain.com/old/small_blue_widget.htm _to this: domain.com/new/small_blue_widget.htm

          To remove the extension would be:

          <code>RewriteRule ^([^\.]+)$ $1.htm [NC,L]</code>
          
          TheDude 1 Reply Last reply Reply Quote 0
          • TheDude
            TheDude @DmitriiK last edited by

            Hey Dmitrii,

            This rewrite that I posted above...

            RewriteRule ^old/(.*)$ /new/$1 [L,R=301]

            ...isn't intended to remove the file extensions. I'm using it to redirect the old directory structure to our new directory structure.

            I was asking if using this rewrite when changing my directory structure will be all I need in regards to having all the necessary redirects in place to not negatively affect our SEO/SERP rankings. Any idea?

            Also, would you recommend the rewrite you provided above over the one below when removing file extensions?

            RewriteBase /
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME}.html -f
            RewriteRule ^(.*)$ $1.html

            Let me know if I'm being clear enough 🙂 Thanks!

            DmitriiK 1 Reply Last reply Reply Quote 0
            • DmitriiK
              DmitriiK @TheDude last edited by

              Yes, I believe so, that's the only rewrite you'd need not to mess up rankings.

              I don't know if one of codes is better than another. All I know that my piece of code is working and i haven't used the one you wrote. It seems ok to me, but just test it. If it works, I don't think there is any difference.

              TheDude 2 Replies Last reply Reply Quote 1
              • TheDude
                TheDude @DmitriiK last edited by

                Thanks for the help Dmitrii!

                Both the rewrite I posted above and yours for removing file extensions failed to work. However, it seems this one does the trick (taken from the Apache help forums).

                RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).htm [NC,OR]
                RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).php [NC]
                RewriteRule ^ %1 [R,L]

                1 Reply Last reply Reply Quote 0
                • TheDude
                  TheDude @DmitriiK last edited by

                  Another question just popped into my head...

                  Once our new website directory structure and URL format has been rewritten, redirected and indexed by search engines, would it make sense to edit the actual webpage file names (replacing the underscores w/ hyphens) and then remove the URL rewrite that replaces the underscores with the hyphens? Or is this not recommended?

                  DmitriiK 1 Reply Last reply Reply Quote 0
                  • DmitriiK
                    DmitriiK @TheDude last edited by

                    Well, I thought that's what you were going to do and use rewrite just for deleting file extensions. Honestly, I'd leave file extensions and rename files to hyphens. This way there is no server processing involved.

                    TheDude 1 Reply Last reply Reply Quote 0
                    • TheDude
                      TheDude @DmitriiK last edited by

                      Hey Dmitrii,

                      I was planning on using two rewrites.

                      One rewrite for replacing the underscores with hyphens.

                      And another rewrite for removing the file extensions.

                      Just so I fully understand, you recommend implementing the rewrite for replacing the underscores with hyphens in our .htaccess file. Then once the new URLs are indexed, change the webpage file names themselves by replacing the underscores with hyphens, make the newly named files live and remove this rewrite from our .htaccess. Is my understanding correct?

                      Again...thanks for all of your help!

                      DmitriiK 1 Reply Last reply Reply Quote 0
                      • DmitriiK
                        DmitriiK @TheDude last edited by

                        I'm saying rename files first and do rewrite for removing extensions.

                        You will have to do rewrite for replacing underscores with hyphens anyway, just for redirect purposes.

                        So, rename files from underscores to hyphens; do rewrite rule for underscore to hyphens to insure old pages are being redirected; do another rewrite for removing file extensions. In som time (2-3-4 months) when old file names (with underscores) are out of google index, delete first rewrite.

                        TheDude 1 Reply Last reply Reply Quote 1
                        • TheDude
                          TheDude @DmitriiK last edited by

                          Thanks for clearing that up and all of the help!

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          • URL Structure & Best Practice when Facing 4+ Sub-levels
                            Seenlyst
                            Seenlyst
                            0
                            4
                            62

                          • Mass URL changes and redirecting those old URLS to the new. What is SEO Risk and best practices?
                            Charles-O
                            Charles-O
                            0
                            6
                            465

                          • Best-practice URL structures with multiple filter combinations
                            digitalcrc
                            digitalcrc
                            0
                            3
                            4.0k

                          • Best Practices
                            RangeMarketing
                            RangeMarketing
                            0
                            6
                            95

                          • What is the best practice for URLs for E-commerce products in multiple categories?
                            LesleyPaone
                            LesleyPaone
                            0
                            4
                            1.4k

                          • Urgent Help - Ecommerce URL best practice for SEO
                            JaneCopland
                            JaneCopland
                            0
                            2
                            177

                          • What's the best SEO practice for having dynamic content on the same URL?
                            Igal_Zeifman
                            Igal_Zeifman
                            0
                            3
                            1.3k

                          • Best practice?
                            Debdulal
                            Debdulal
                            0
                            4
                            265

                          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