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 SEO Practices for Displaying FAQs throughout site?
I've got an FAQ plugin (Ultimate FAQ) for a Wordpress site with tons of content (like 30 questions each with a page full, multi-paragraphs, of answers with good info -- stuff Google LOVES.) Right now, I have a main FAQ page that has 3 categories and about 10 questions under each category and each question is collapsed by default. You click an arrow to expand it to reveal the answer.I then have a single category's questions also displayed at the bottom of an appropriate related page. So the questions appear in two places on the site, always collapsed by default.Each question has a permalink that links to an individual page with only that question and answer.I know Google discounts (doesn't ignore) content that is hidden by default and requires a click (via js function) to reveal it.So what I'm wondering is if the way I have it setup is optimal for SEO? How is Google going to handle the questions being in essentially three places: it's own standalone page, in a list on a category page, and in a list on a page showing all questions for all categories. Should I make the questions not collapsed by default (which will make the master FAQ page SUPER long!)Does Google not mind the duplicate content within the site?What's the best strategy?
Intermediate & Advanced SEO | | SeoJaz0 -
Best practice to redirect http to https
I have an SSL certificate on our domain but at times some search results still list the HTTP version. Clicking on this then warns the user about security and they leave. To avoid this I am using this in the htaccess file to redirect all HTTP visits to the https version. RewriteEngine On
Intermediate & Advanced SEO | | Gavpeds
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L] Is this ok? I notice on Moz toolbar it give a 302 temporary redirect I am thinking this isn't good and needs to be a 301 maybe? What is the best practice in this situation?1 -
Faceted Navigation URLs Best Practices
Hi, We are developing new Products Pages with faceted filters. You can see it here: https://www.viatrading.com/wholesale-products/ We have a feature allowing to Order By and Group By, which alters the order of all products. There will also be the option to view Products as a table, which will contain same products but with different design and maybe slightly different content of each product. All this will happen without changing the URL, https://www.viatrading.com/all/ Is this the best practice? Thanks,
Intermediate & Advanced SEO | | viatrading10 -
Best SEO practice for multiple languages in website
HI, We would like to include multiple languages for our global website. What's the best practice to gain from UI and SEO too. Can we have auto language choosing website as per browsing location? Or dedicated pages for important languages like www.website.com/de for German. If we go for latter, how about when users browsing beside language page as they will be usually in English
Intermediate & Advanced SEO | | vtmoz0 -
Best practice for retiring old product pages
We’re a software company. Would someone be able to help me with a basic process for retiring old product pages and re-directing the SEO value to new pages. We are retiring some old products to focus on new products. The new software has much similar functionality to the old software, but has more features. How can we ensure that the new pages get the best start in life? Also, what is the best way of doing this for users? Our plan currently is to: Leave the old pages up initially with a message to the user that the old software has been retired. There will also be a message explaining that the user might be interested in one of our new products and a link to the new pages. When traffic to these pages reduces, then we will delete these pages and re-direct them to the homepage. Has anyone got any recommendations for how we could approach this differently? One idea that I’m considering is to immediately re-direct the old product pages to the new pages. I was wondering if we could then provide a message to the user explaining that the old product has been retired but that the new improved product is available. I’d also be interested in pointing the re-directs to the new product pages that are most relevant rather than the homepage, so that they get the value of the old links. I’ve found in the past that old retirement pages for products can outrank the new pages as until you 301 them then all the links and authority flow to these pages. Any help would be very much appreciated 🙂
Intermediate & Advanced SEO | | RG_SEO0 -
URL blocked
Hi there, I have recently noticed that we have a link from an authoritative website, however when I looked at the code, it looked like this: <a <span="">href</a><a <span="">="http://www.mydomain.com/" title="blocked::http://www.mydomain.com/">keyword</a> You will notice that in the code there is 'blocked::' What is this? has it the same effect as a nofollow tag? Thanks for any help
Intermediate & Advanced SEO | | Paul780 -
Changing my url name? Should I do it?
Hi, I am targeting a brand called Creative Recreation, who are a trainers brand. We currently rank ok-ish for certain terms for Creative Recreation Trainers, Footwear and Creative Recreation [INSERT STYLE NAME HERE]. Our main search term I think we would like to improve on is "creative recreation trainers" as we are 6th for this. Our domain name points to the brands page as designerboutique-online.com/all-clothing/creative-recreation/ Now what I want to know is, would it be worthwhile or would it affect my current rank/index if I changed the end of that url to read /creative-recreation-trainers/ thus getting the keyword phrase in the url? Creative-Recreation is a hard one to crack as you have a lot of competition from the brands site etc.. Any ideas on this? Cheers Will
Intermediate & Advanced SEO | | YNWA0 -
How important is it to clarify URL parameters?
We have a long list of URL parameters in our Google Webmasters account. Currently, the majority are set to 'let googlebot decide.' How important is it to specify exactly what googlebot should do? Would you leave these to 'let googlebot decide' or would you specify how googlebot should treat each parameter?
Intermediate & Advanced SEO | | nicole.healthline0