undefined
Skip to content
Moz logo Menu open Menu close
  • Products
    • Moz Pro
    • Moz Pro Home
    • Moz Local
    • Moz Local Home
    • STAT
    • Moz API
    • Moz API Home
    • Compare SEO Products
    • Moz Data
  • Free SEO Tools
    • Domain Analysis
    • Keyword Explorer
    • Link Explorer
    • Competitive Research
    • MozBar
    • More Free SEO Tools
  • Learn SEO
    • Beginner's Guide to SEO
    • SEO Learning Center
    • Moz Academy
    • SEO Q&A
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • Case Studies
    • The Moz Story
    • New Releases
  • Log in
  • Log out
  • Products
    • Moz Pro

      Your all-in-one suite of SEO essentials.

    • Moz Local

      Raise your local SEO visibility with complete local SEO management.

    • STAT

      SERP tracking and analytics for enterprise SEO experts.

    • Moz API

      Power your SEO with our index of over 44 trillion links.

    • Compare SEO Products

      See which Moz SEO solution best meets your business needs.

    • Moz Data

      Power your SEO strategy & AI models with custom data solutions.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Free SEO Tools
    • Domain Analysis

      Get top competitive SEO metrics like DA, top pages and more.

    • Keyword Explorer

      Find traffic-driving keywords with our 1.25 billion+ keyword index.

    • Link Explorer

      Explore over 40 trillion links for powerful backlink data.

    • Competitive Research

      Uncover valuable insights on your organic search competitors.

    • MozBar

      See top SEO metrics for free as you browse the web.

    • More Free SEO Tools

      Explore all the free SEO tools Moz has to offer.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Learn SEO
    • Beginner's Guide to SEO

      The #1 most popular introduction to SEO, trusted by millions.

    • SEO Learning Center

      Broaden your knowledge with SEO resources for all skill levels.

    • On-Demand Webinars

      Learn modern SEO best practices from industry experts.

    • How-To Guides

      Step-by-step guides to search success from the authority on SEO.

    • Moz Academy

      Upskill and get certified with on-demand courses & certifications.

    • SEO Q&A

      Insights & discussions from an SEO community of 500,000+.

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • Small Business Solutions

      Uncover insights to make smarter marketing decisions in less time.

    • Agency Solutions

      Earn & keep valuable clients with unparalleled data & insights.

    • Enterprise Solutions

      Gain a competitive edge in the ever-changing world of search.

    • The Moz Story

      Moz was the first & remains the most trusted SEO company.

    • Case Studies

      Explore how Moz drives ROI with a proven track record of success.

    • New Releases

      Get the scoop on the latest and greatest from Moz.

    Surface actionable competitive intel
    New Feature

    Surface actionable competitive intel

    Learn More
  • Log in
    • Moz Pro
    • Moz Local
    • Moz Local Dashboard
    • Moz API
    • Moz API Dashboard
    • Moz Academy
  • Avatar
    • Moz Home
    • Notifications
    • Account & Billing
    • Manage Users
    • Community Profile
    • My Q&A
    • My Videos
    • Log Out

The Moz Q&A Forum

  • Forum
  • Questions
  • Users
  • Ask the Community

Welcome to the Q&A Forum

Browse the forum for helpful insights and fresh discussions about all things SEO.

  1. Home
  2. SEO Tactics
  3. Intermediate & Advanced SEO
  4. URL Rewriting Best Practices

Moz Q&A is closed.

After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

URL Rewriting Best Practices

Intermediate & Advanced SEO
2
12
5.2k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • TheDude
    TheDude Subscriber last edited by Nov 10, 2015, 6:07 PM

    Hey Moz!

    I’m getting ready to implement URL rewrites on my website to improve site structure/URL readability. More specifically I want to:

    • Improve our website structure by removing redundant directories.
    • Replace underscores with dashes and remove file extensions for our URLs.

    Please see my example below:

    Old structure: http://www.widgets.com/widgets/commercial-widgets/small_blue_widget.htm

    New structure: https://www.widgets.com/commercial-widgets/small-blue-widget

    I've read several URL rewriting guides online, all of which seem to provide similar but overall different methods to do this. I'm looking for what's considered best practices to implement these rewrites. From what I understand, the most common method is to implement rewrites in our .htaccess file using mod_rewrite (which will find the old URLs and rewrite them according to the rewrites I implement).

    One question I can't seem to find a definitive answer to is when I implement the rewrite to remove file extensions/replace underscores with dashes in our URLs, do the webpage file names need to be edited to the new format? From what I understand the webpage file names must remain the same for the rewrites in the .htaccess to work. However, our internal links (including canonical links) must be changed to the new URL format. Can anyone shed light on this?

    Also, I'm aware that implementing URL rewriting improperly could negatively affect our SERP rankings. If I redirect our old website directory structure to our new structure using this rewrite, are my bases covered in regards to having the proper 301 redirects in place to not affect our rankings negatively?

    Please offer any advice/reliable guides to handle this properly.

    Thanks in advance!

    1 Reply Last reply Reply Quote 0
    • TheDude
      TheDude Subscriber @DmitriiK last edited by Nov 12, 2015, 1:16 PM Nov 12, 2015, 1:16 PM

      Thanks for clearing that up and all of the help!

      1 Reply Last reply Reply Quote 0
      • DmitriiK
        DmitriiK @TheDude last edited by Nov 12, 2015, 1:16 PM Nov 12, 2015, 1:12 PM

        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 Nov 12, 2015, 1:16 PM Reply Quote 1
        • TheDude
          TheDude Subscriber @DmitriiK last edited by Nov 12, 2015, 1:03 PM Nov 12, 2015, 1:03 PM

          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 Nov 12, 2015, 1:12 PM Reply Quote 0
          • DmitriiK
            DmitriiK @TheDude last edited by Nov 12, 2015, 12:55 PM Nov 12, 2015, 12:55 PM

            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 Nov 12, 2015, 1:03 PM Reply Quote 0
            • TheDude
              TheDude Subscriber @DmitriiK last edited by Nov 12, 2015, 12:41 PM Nov 12, 2015, 12:41 PM

              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 Nov 12, 2015, 12:55 PM Reply Quote 0
              • TheDude
                TheDude Subscriber @DmitriiK last edited by Nov 11, 2015, 6:06 PM Nov 11, 2015, 2:36 PM

                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
                • DmitriiK
                  DmitriiK @TheDude last edited by Nov 11, 2015, 2:35 PM Nov 11, 2015, 2:17 PM

                  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 Nov 12, 2015, 12:41 PM Reply Quote 1
                  • TheDude
                    TheDude Subscriber @DmitriiK last edited by Nov 11, 2015, 2:04 PM Nov 11, 2015, 2:04 PM

                    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 Nov 11, 2015, 2:17 PM Reply Quote 0
                    • DmitriiK
                      DmitriiK @TheDude last edited by Nov 11, 2015, 12:29 PM Nov 11, 2015, 12:29 PM

                      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 Nov 11, 2015, 2:04 PM Reply Quote 0
                      • TheDude
                        TheDude Subscriber @DmitriiK last edited by Nov 11, 2015, 11:00 AM Nov 11, 2015, 10:29 AM

                        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 Nov 11, 2015, 12:29 PM Reply Quote 0
                        • DmitriiK
                          DmitriiK last edited by Nov 11, 2015, 11:14 AM Nov 10, 2015, 7:27 PM

                          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 Nov 11, 2015, 10:29 AM Reply Quote 1
                          • 1 / 1
                          1 out of 12
                          • First post
                            1/12
                            Last post

                          Got a burning SEO question?

                          Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


                          Start my free trial


                          Browse Questions

                          Explore more categories

                          • Moz Tools

                            Chat with the community about the Moz tools.

                          • SEO Tactics

                            Discuss the SEO process with fellow marketers

                          • Community

                            Discuss industry events, jobs, and news!

                          • Digital Marketing

                            Chat about tactics outside of SEO

                          • Research & Trends

                            Dive into research and trends in the search industry.

                          • Support

                            Connect on product support and feature requests.

                          • See all categories

                          Related Questions

                          • Davit1985

                            My url disappeared from Google but Search Console shows indexed. This url has been indexed for more than a year. Please help!

                            Super weird problem that I can't solve for last 5 hours. One of my urls: https://www.dcacar.com/lax-car-service.html Has been indexed for more than a year and also has an AMP version, few hours ago I realized that it had disappeared from serps. We were ranking on page 1 for several key terms. When I perform a search "site:dcacar.com " the url is no where to be found  on all 5 pages. But when I check my Google Console it shows as indexed I requested to index again but nothing changed. All other 50 or so urls are not effected at all, this is the only url that has gone missing can someone solve this mystery for me please. Thanks a lot in advance.

                            Intermediate & Advanced SEO | Apr 8, 2019, 8:19 AM | Davit1985
                            0
                          • ColesNathan

                            Is it best practice to have a canonical tags on all pages

                            The website I'm working on has no canonical tags. There is duplicate content so rel=canonicals need adding to certain pages but is it best practice to have a tag on every page ?

                            Intermediate & Advanced SEO | Sep 8, 2018, 3:58 PM | ColesNathan
                            0
                          • andyheath

                            Will disallowing URL's in the robots.txt file stop those URL's being indexed by Google

                            I found a lot of duplicate title tags showing in Google Webmaster Tools. When I visited the URL's that these duplicates belonged to, I found that they were just images from a gallery that we didn't particularly want Google to index. There is no benefit to the end user in these image pages being indexed in Google. Our developer has told us that these urls are created by a module and are not "real" pages in the CMS. They would like to add the following to our robots.txt file Disallow: /catalog/product/gallery/ QUESTION: If the these pages are already indexed by Google, will this adjustment to the robots.txt file help to remove the pages from the index? We don't want these pages to be found.

                            Intermediate & Advanced SEO | Apr 28, 2016, 11:05 AM | andyheath
                            0
                          • jayoliverwright

                            Duplicate URLs ending with #!

                            Hi guys, Does anyone know why a site can contain duplicate URLs ending with hastag & exclamation mark e.g. https://site.com.au/#! We are finding a lot of these URLs (as duplicates) and i was wondering what they are from developer standpoint? And do you think it's worth the time and effort adding a rel canonical tag or 301 to these URLs eventhough they're not getting indexed by Google? Cheers, Chris

                            Intermediate & Advanced SEO | Nov 2, 2015, 5:34 PM | jayoliverwright
                            0
                          • _nitman

                            What's the best possible URL structure for a local search engine?

                            Hi Mozzers, I'm working at AskMe.com which is a local search engine in India i.e if you're standing somewhere & looking for the pizza joints nearby, we pick your current location and share the list of pizza outlets nearby along with ratings, reviews etc. about these outlets. Right now, our URL structure looks like www.askme.com/delhi/pizza-outlets for the city specific category pages (here, "Delhi" is the city name and "Pizza Outlets" is the category) and www.askme.com/delhi/pizza-outlets/in/saket for a category page in a particular area (here "Saket") in a city. The URL looks a little different if you're searching for something which is not a category (or not mapped to a category, in which case we 301 redirect you to the category page), it looks like www.askme.com/delhi/search/pizza-huts/in/saket if you're searching for pizza huts in Saket, Delhi as "pizza huts" is neither a category nor its mapped to any category. We're also dealing in ads & deals along with our very own e-commerce brand AskMeBazaar.com to make the better user experience and one stop shop for our customers. Now, we're working on URL restructure project and my question to you all SEO rockstars is, what can be the best possible URL structure we can have? Assume, we have kick-ass developers who can manage any given URL structure at backend.

                            Intermediate & Advanced SEO | Aug 8, 2015, 1:46 AM | _nitman
                            0
                          • Atlanta-SMO

                            Does Google Read URL's if they include a # tag? Re: SEO Value of Clean Url's

                            An ECWID rep stated in regards to an inquiry about how the ECWID url's are not customizable, that "an important thing is that it doesn't matter what these URLs look like, because search engines don't read anything after that # in URLs. " Example http://www.runningboards4less.com/general-motors#!/Classic-Pro-Series-Extruded-2/p/28043025/category=6593891 Basically all of this: #!/Classic-Pro-Series-Extruded-2/p/28043025/category=6593891 That is a snippet out of a conversation where ECWID said that dirty urls don't matter beyond a hashtag... Is that true? I haven't found any rule that Google or other search engines (Google is really the most important) don't index, read, or place value on the part of the url after a # tag.

                            Intermediate & Advanced SEO | Oct 11, 2014, 2:26 PM | Atlanta-SMO
                            0
                          • Michael-Goode

                            Domain Name Change - Best Practices?

                            Good day guys, We got a restaurant that is changing its name and domain. However they are keeping the same server location, same content and same pages (we are just changing the logo on the website). It just has to go a new domain. We don't want to lose the value of the current site, and we want to avoid any duplicate penalties. Could you please advise of the best practices of doing a domain name change? Thank you.

                            Intermediate & Advanced SEO | Jul 30, 2012, 2:57 PM | Michael-Goode
                            0
                          • WebMarketingandDesign

                            Multiple URLs for the same page

                            I am working with a client and recently discovered that they have several URLs that go to the same page. http://www.maps.com/FunFacts.aspx
                            http://www.maps.com/funfacts.aspx
                            http://www.maps.com/FunFacts.aspx?nav=FF
                            http://www.maps.com/FunFacts.aspx?nav=FS
                            http://www.maps.com/funfacts.aspx?nav=FF
                            http://www.maps.com/funfacts.aspx?nav=ffhttp://www.maps.com/FunFacts.aspx?nav=MShttp://www.maps.com/funfacts.aspx?nav=
                            http://www.maps.com/FunFacts.aspx?nav=FF#
                            http://www.maps.com/FunFacts
                            http://www.maps.com/funfacts.aspx?.nav=FF I am afraid this is happening all over the site. So, my question is: Is this hurting the SEO and how? If so what is the best way to go about fixing this problem? Thanks for your help!

                            Intermediate & Advanced SEO | Nov 17, 2011, 11:15 PM | WebMarketingandDesign
                            0

                          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
                          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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                          • Accessibility
                          • Terms of Use
                          • Privacy

                          Looks like your connection to Moz was lost, please wait while we try to reconnect.