URL Rewriting Best Practices
-
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!
-
Thanks for clearing that up and all of the help!
-
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.
-
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!
-
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.
-
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?
-
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] -
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.
-
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.htmlLet me know if I'm being clear enough Thanks!
-
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>
-
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>
-
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.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
Best practice to redirect all 404s?
Hey is it best practice to redirect all 404 pages. For example if the 404 pages had 0 traffic and no links why would you need to redirect that page? Isn't it best practice just to leave as a 404? Cheers.
Intermediate & Advanced SEO | | kayl870 -
Trailing Slashes on URLs
Hi we currently have a site on Wordpress which has two version of each URL trailing slash on URLs and one without it. Example: www.domain.com/page (preferred version - based on link data) www.domain.com/page**/** The non-slash version of the URL has most of the external links pointing to them, so we are going to pick that as the preferred version. However, currently, each version of every URL has rel canonical tag pointing to the non-preferred version. E.g. www.domain.com/page the rel canonical tag is: www.domain.com/page/ What would be the best way to clean up this setup? Cheers.
Intermediate & Advanced SEO | | cathywix0 -
Confused: Url Restructure
Hello, We're giving our website a bit of a spring clean in terms of SEO. The site is doing ok, but after the time invested in SEO, content and last year's migration of multiple sites into one, we're not seeing the increase in traffic we had hoped. Our current urls look something like this: /a-cake-company/cup-cakes/strawberry We have the company name as the first level as we with the migration we migrated many companies into one site. What we're considering is testing some pages with a structure like this: /cup-cakes/cup-cake-company-strawberry So we'll lose a level and we'll focus more on the category of the product rather than the brand. What's your thoughts on this? We weren't going to do a mass change yet, just a test, but is this something we should be focusing on? In terms of organisation our current url structure is perfect, but what about from an SEO point of view? In terms of keywords customers are looking for both options. Thanks!
Intermediate & Advanced SEO | | HB170 -
Canonical URL availability
Hi We have a website selling cellphones. They are available in different colors and with various data capacity, which slightly changes the URL. For instance: Black iphone, 16GB: www.site.com/iphone(black,16,000000000010204783).html White iphone, 16GB: www.site.com/iphone(white,16,000000000010204783).html White iphone, 24GB: www.site.com/iphone(white,24,000000000010204783).html Now, the canonical URL indicates a standard URL: But this URL is never physically available. Instead, a user gets 301 redirected to one of the above URLs. Is this a problem? Does a URL have to be "physically" available if it is indicated as canonical?
Intermediate & Advanced SEO | | zeepartner0 -
Switching Url
I started working with a Roofer/Contractor about a year ago. His website is http://www.lancasterparoofing.com/. The name of his business is Spicher Home Improvements. He used to have spicherhomeimprovements.com, well he still does. He was focusing on Roofing and Siding but now would like to branch to other areas like Interior remodeling. So adding interior work under LancasterPaRoofing.com is not applicable. I do not think starting another domain and having two is the best option. I think he should go back to using SpicherHomeImprovements.com and I assume he would take a small hit but in time he should be better off. Plus the url is more applicable to the real name of his business. Thanks for any feedback I receive. Chad
Intermediate & Advanced SEO | | ChadEisenhart0 -
SEO Best Practice for a multi-language and multi-country website
Hello Moz Community, I hope someone could help me identify the best action to take on an on-page optimization confusion I am currently having. The website I am currently trying to optimize is http://www.riafinancial.com/locations/us/home.aspx. There is an option to view a country specific version of the page, or language version (there are 2 drop down menus on the top, for country or for language). When viewing a country specific version of the page, the URL changes depending on country selected. Some country versions also updates the content to the language of that country, but some remain English. Example, when viewing the France version of the page (http://www.riafinancial.com/locations/FR/home.aspx), the content is updated to french version, but when viewing the China version (http://www.riafinancial.com/locations/CN/home.aspx), the content is in English. This is because we have not yet translated for all countries (this will eventually be all translated). Now, when viewing by language, the URL does NOT change. Example, in http://www.riafinancial.com/locations/us/home.aspx, you can choose French, German, Italian, Polish, etc. The content of the page will change based on language chosen, but the URL (including page titles, meta-descriptions) will not change. My question is, how should I approach this for on-page optimization? Canonical? Hreflang? Any input, feedback, recommendation, suggestion will be greatly appreciated. Thanks! Sharon
Intermediate & Advanced SEO | | RiaMT0 -
Rewriting URL
I'm doing a major URL rewriting on our site to make the URL more SEO friendly as well as more comfortable and intuitive for our users. Our site has a lot of indexed pages, over 250k. So it will take Google a while to reindex everything. I was thinking that when Google Bot encounters the new URLs, it will probably figure out it's duplicate content with the old URL. At least until it recrawls the old URL and get a 301 directing them to the new URL. This will probably lower the ranking of every page being crawled. Am I right to assume this is what will happen? Or is it fine as long as the old URLs get 301 redirect? If it is indeed a problem, what's the best solution? rel="canonical" on every single page maybe? Another approach? Thank you.
Intermediate & Advanced SEO | | corwin0 -
Best practice?
Hi there, I have recently written an article which I have posted on an online newspaper website. I want to use this article and put it on my blog also, the reason the article will be placed on my blog is to drive users from my email marketing activities. Would it simply be best practice to disallow Google from crawling this page? or put a rel canonical on the article placed on my blog pointing to the article placed on the online newspaper website? Thanks for any suggestions
Intermediate & Advanced SEO | | Paul780