URL rewrites and 301 redirects... you talk about them, you recommend them, but do you truly understand how they work? Sure, you know that rewriting a URL means that the URL displayed in the browser changes to be more SEO (and user) friendly. And you know that a 301 redirect is a permanent redirect. But let's dig a little deeper, and explain how they work together.
As a developer, my very first SEO project was the task of rewriting a massive number of URLs and ensuring that the old URL redirected to the new. It was a daunting task at first because I didn't have a clear understanding of how it all worked together. I was sure I'd have to rewrite pages and pages of code, and spend weeks if not months on the project. But once I figured it all out, the light bulb went on, and it literally took just a couple days to get it right. Yep! Days.
URL Rewrites
Rewriting a URL means changing the way the URL is displayed in the browser. When a user lands on a page with a rewritten URL, the code behind that page doesn't change. In fact, the server still reads the original URL.
URL Rewrite Process:
- User lands on new SEO'd URL
- Using mod_rewrite, ISAPI_Rewrite, etc. new URL points to old URL on the server
- Server calls the code from the old URL
- Page is displayed in browser, displaying the new URL
From the server's perspective, nothing has changed. The code is still the same. For example, if a developer had built a site using URL variables, there's no need to change any code. Now, there are always cases that could contradict this. But at the basic level, there shouldn't be a need to change code on the page.
301 Redirect
Once the URL is rewritten, you want to make sure that the old URL 301 redirects to the new. This tells the search engines that any link equity the old URL had should now be given to the new URL. It also makes for a good user experience, rather than showing a 404 error page. The server is told URL A should now be URL B.
301 Redirect Process:
- User lands on original URL
- Using code, mode_rewrite, etc. the 301 redirects URL to the new one, literally changing the URL that is displayed in the browser from the old to the new
- URL Rewrite process begins again
Using the rewrite and redirect together brings the solution full circle. I've trained many developers on SEO standards and specifically how to implement and understand the workings of the rewrites and redirects. It takes a bit to wrap your head around it, but it's all really quite simple.
For more detailed information on rewrites and redirects, check out the following sites:
- Our Guide to Applying 301 Redirects with Apache
- Apache mod rewrite
- IIS - ISAPI_Rewrite
- URLRewriter.net - Open Source URL Rewriter for .NET / IIS / ASP.NET
- Creating 301 Redirects in various languages
Personally, I find it fascinating and enjoy helping SEO's as well as developers "see the light," as I like to call it. It's that "aha" moment when they realize how simple it all is, and how easy it is to make your site SEO friendly. The best part is that rewriting URLs also helps to improve user experience. I'd love to hear if you have something to add, or how you go about explaining how these functions work together.
One trick I did is modify the 404 error pages. Before sending the actual 404 code, I check the requested URL to see if this one is include in a array of old url->new url. If so, I do a 301 redirection to the new url and return a 301 code instead. It's easier to modify the array list from my CMS (1 page to modify) than modify the Apache config file/restarting the web server or create a new .htaccess file.
This is a good method for redirecting as well. There really is no one solution, since every website is slightly different. Thanks for bringing this up!
Once the 404 status code has been returned by the HTTP Headers it is too late to send any sort of HTTP redirect to the browser. Therefore you cannot do this by modifying your 404 pages.
You *can* do this by modifying your forum script so it directly sends a 404 HTTP Header out. The script sends either 404 or 301, or returns valid content. It is vital to have this functionality, otherwise your site will return '200 OK' and a blank template for any and every requested URL.
What about old URL's that don't exist anymore and bring up a 404? The content no longer exists (let's say the product has been discontinued for example). Is it best to:
a) redirect that old product specific page to a relatively similar product page or the main product page or homepage.
b) leave it alone, assuming Google will remove the error page from its index in time.
What is the best way to handle a scenerio like this where the content is no longer in existence, not that the URL just changed?
DanaDV,
Good question.
I would think that the solution depends on if you want the URL to stick around permemantly or if you want them to eventually go away and if the page has any external links pointing to it.
I typically will 301 redirect those pages for a 3-6 month term if they do not have any external links to them and remove any internal links. The issue tends to resolve it self in a few months as the engines remove them from their index in this scenario.
If they do have external links then the issue becomes a little more complex based on the fact that I usually do not like to lose existing links.
I might move content from another page without external link popularity to this one and 301 the page that the original content was moved from. This might depend on the file name of the pages. I might move content from /blue-widgets.htm to /widgets-online.htm if, like this example, the file name was not misleading. However I probably would not move /blue-widgets.htm to /red-widgets.htm.
In a similar manner, you could copy content from the /blue-widgets.htm to /widgets-online.htm and use the rel="canonical" tag to clarify that the content on the /widgets-online.htm should be associated with the /blue-widgets.htm page. This solution would have the highest chanceof retaining existing links to the page.
You could also copy or create another version of a main category page to display here and use the rel="canonical" tag. For instance for the /blue-widgets.htm page you might use the content from a main /widgets.htm page.
How to solve this situation also might just depend on the CMS and server capabilities that the site is hosted on.
my 2.0 cents...
P.S. Great Post! I love the use of the graphics.
James,
In your reply, you mentioned that one solution would be to use the rel="canonical" tag to clarify that "the content on the /widgets-online.htm should be associated with the /blue-widgets.htm." How do you clarify this?
In other words, if you place the rel="canonical" tag on the /widgets-online.htm page, how do the search engines know that the other page is associated with it" Because they have the same body content? Or can you clarify it in the tag?
I wonder how similar the pages have to be for the engines to figure this out. Do you think they would ever make a mistake?
westgate,
The rel="canonical" tag is basically a meta tag that goes in the <head> section of the page. It has only been around since February so I have not had enough time to test and analyze it fully, but the common assumption is that the search engines interpret its function in a similar manner as a 301 redirect.
This is the blank/default tag:
<link rel="canonical" href="" />
In this scenario, this is the full tag that would be placed in the head section of the old /widgets-online.htm URL to associate that content/page with the /blue-widgets.htm page.
<link rel="canonical" href="https://www.widgetsforsale.com/blue-widgets.htm" />
Also, Rand wrote a nice post on the Canonical URL Tag that will help better explain it.
James:
Thanks a lot for your explanation. What you're saying makes a lot of sense, and I appreciate the detail.
Hi! Rand actually did a Whiteboard Friday about Expiring Content just last week. I think it depends on the type of content that has expired/discontinued but I have seen exceptional results by 301 redirecting the expired pages to the category page the original product lived under. Essentially this points many expiring pages to one category page, which gives that one page more authority than having a bunch of individual pages roaming around.
Redirecting expired pages to the category page is great when both are on the same topic. That's a very useful thing to do.
If there's no matching section, sending a 404, or even perhaps 410, is the right thing to do.
Other types of mass-redirection can often be dangerous, especially redirecting a whole site to the root.
Awesomely coincidental.
One of our dev managers scheduled a meeting with SEOs on one side and the dev team leads on the other to discuss:
"Defining a method for managing URL rewriting across SEO initiatives."
Corporate-speak aside, I suspect he wants to talk about when our devs should be using 301 redirects vs. URL rewrites.
I sent him your article, fingers crossed it answers most of his questions!
You need a redirect to a different URL when:
- people are attempting to access content at a non-canonical URL, or
- the page has moved to a new location.
You need a rewrite:
- to connect an incoming URL request to a different format for the path, and/or a different file name, to that which is suggested by the path part within the original client request.
SEO People I believe either come from any of these 4 professions:
1) Writing/Journalism
2) Marketing
3) IT/Technical/Design/Development
Some coming from #3 might say "Yeah, this is common sense, I knew that already, nothing special blah blah..."
But to those tech people, bear in mind that SEO people are also #1 and #2 and may not get the concepts right away. Good blog post.
I'm actually a #1 and #3 :). I've known many many developers who did not understand how rewrites and redirects worked. Heck I was one of them at one point. So definitely don't assume that every techie you talk to clearly understands how it works.
With a 301, the web server sends an HTTP Header to the user's browser containing the new URL. The user's browser reads this header and prepares a new HTTP request to the new URL.
This usually happens quickly enough that it seems seamless to the person looking at the brower; however, you should take into account the added "internet travel time" when trying to decide whether to use a 301 redirect or a rewrite.
One nice thing about the 301 redirect is that the original referring URL is retained in the second HTTP request, which is useful in your web stats (you don't want your referrer to appear as the 301-ing URL). - if you have 4 different URLs for the same file and want one to be "authoritative" on the search engines, it's usually best to consolidate those with 301 rather than retain the separate URLs. Canonical URLs are another option, but that's a pretty new thing, and more appropriate when you're hiding paginated query parameters and such.
Your browser should send the same referrer as original on the second (redirected) request.
That is, the original referrer value should be preserved after the redirect.
It is very easy to test that!
If you don't change code inside the pages / content, then you will still generate and display the old urls?
Those will get redirected, no doubt, but each page load will be a 301 followed by a 200. Thats probably not ideal, but I don't know how the crawlers treat that. It will slow down the overall page load time, as a second request is made first.
Good pont 0lly,
It's very stupid to left old links in the code. For sure, Jennita has forgotten to mention this step.
You have to change code manually to point to new links or, for lazy people, there is an another option https://www.helicontech.com/linkfreeze/ - "LinkFreeze is a fast and easy solution to optimize dynamic or database-driven website for search engines. It optimizes dynamic links on your site by substituting all unwanted characters and making links look like static file links." - I don't tried it, don't know how it works.
0lly and break787 thanks for bringing this up, and you're right! You will definitely need to change the URLs within the site. However this normally happens on the pages pointing to the new rewritten URLs.
My point about not having to change code was mainly directed at the fact that if your old URL used querystring variables, you wouldn't have to change the code on your page to use something else. You can continue to use those variables. There will definitely need to be changes throughout the site whenever you make major overhauls. And every website is set up differently, so you'll need to make changes as needed.
Thanks for pointing this out!
If you want users to 'see' and 'use' new URLs you must change the links on your pages to use these new URLs.
It is not acceptable to use the old links on your pages, because every click will result in the user passing through a 301 redirect to hit the content at the new URL.
Clicking internal navigation should never trigger a redirect. The on-page links should use the new URLs. It is these links that 'define' URLs.
The only purpose of the redirect is to cater for clients that have stored references to the old URLs in their browser bookmarks, and search engines URL databases. The redirect forces them to update their systems to refer to the new URLs.
Recently, I made this process for a well-known website in the "art supplies" field. That site had thousand and thousand of product pages. The redirection from old URLs to new URLs was really difficult because the old and new structure are really different. In fact, the only way that I found to do it was by writing the rules in the ISAPI configuration file manually... this solution would be really time consuming. Anyway, the final solution was: to make redirections from a lot of old URLs to homepage in order to avoid 404 errors and ranking drops on Google. Fortunately, this solution worked well and the website has increased the sales :-)
Mass redirection to one page can often be a bad idea.
You should redirect to the nearest equivalent-content page, and where an equivalent does not exist, you really should send a 404, or even better, send a 410 response.
Mass redirection to the root is often a bad plan, especially if the redirect also works for URLs that have never existed on your site.
Hi Jen.
Lets say you use .htaccess to implement a mod_rewrite, then want to use .htaccess to do your 301 redirects as well (let's face it, that's the cleanest approach).
Unless I'm very much mistaken, this results in an infinite redirect loop, because although a rewrite isn't technically a redirect it seems to be treated as such by Apache.
Have you found a way around this? Ideally you'd want your 301 redirects to be conditional on the page that is redirecting not being accessed via a rewrite, but I don't think that's possible with .htacess, is it?
Is there no recourse but to use PHP/ASP in your templates to carry out the 301 redirect conditionally?
I mix 301 redirects and mod_rewrite in my .htaccess file all the time. Here's an example .htaccess file:
Post an example of where you get into infinite loop trouble and I'll see if I can help.
Whitespark, thanks for the reply.
But the redirects you have there don't conflict directly with the rewrite, furthermore the rewrite you have is actually a 301 redirect.
I'm talking about the situation described in the original post where you are rewriting some clean URLs to the messy URLs in the background (not redirecting), but also implementing a 301 redirect from the messy URLs to the clean URLs
Simplified, something like:
Redirect permanent messyURL cleanURL
RewriteRule cleanURL messy URL
(sorry don't have an actual .htaccess example to hand).
Ulysses,
I see what you're saying. You're concerned that there will be a continuous loop because the rewrite points to the old URL which you've specified to do a 301 redirect for? I've actually never found this to be an issue, however often times I have added the 301 redirect in the code of the page because I also need to do other things. For example, in one instance I added it to the code because I was not only looking to see whether the page should be redirected, but also whether it was an expired page. If the latter were the case then I did something different with those pages. So I needed the conditional statements in the code, and adding it to ISAPI_Rewrite (in that instance it was IIS server) wasn't going to work.
Hope this helps a bit. :)
QUOTE:[quote]Simplified, something like:
Redirect permanent messyURL cleanURL
RewriteRule cleanURL messy URL[/quote]
Part of the confusion with external redirects and internal rewrites is in unclear use of terminology:
Make this simple change to your thoughts:
[quote]RewriteRule ^messyURLpath example.com/cleanURLpath [R=301,L]
RewriteRule ^cleanURLpath /MessyInternalServerPath [L][/quote]
A redirect makes the browser request a new URL. The target is a URL; that is, you must include the domain name in the target of the redirect and the [R=301,L] flag. Beware that omitting the [R] flag or using just [R] gives an unwanted 302 redirect.
A rewrite connects a URL request with an internal server filepath (it is wrong to call this a 'URL'). The rewrite does not include the domain name and must not use the [R] flag.
*** I mix 301 redirects and mod_rewrite in my .htaccess file all the time. ***
This is extremely dangerous.
Redirect and RedirectMatch come from Mod_Alias.
RewriteRule comes from Mod_Rewrite.
The order that rules in the .htaccess file are evaluated is the reverse order to that which the modules are loaded by Apache as listed in the httpd.conf file.
If the order of loading is reversed (when you perform a server upgrade, or move to a new host), you will end up exposing your internal path parts back out into the URL, and/or creating a multi-step redirection chain.
This can cause Duplicate Content indexing and erode your listings in the SERPs.
If you use RewriteRule for *any* of your rules, you must make sure that you use it for *all* of the rules.
*** Unless I'm very much mistaken, this results in an infinite redirect loop ***
This is easily fixed. Use two RewriteRules.
List the 301 redirect first. Make sure that it also forces the correct domain name at the same time.
List the rewrite last. Precede the RewriteRule with a single RewriteCond that tests THE_REQUEST. That is, only invoke the Rewrite for Direct Client Requests.
[quote]RewriteRule ^messyURL example.com/cleanURLpath [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST) /cleanURLpath HTTP/
RewriteRule ^cleanURLpath /MessyInternalServerPath [L][/quote]
Note that I refer to the "internal server path" here. It is wrong to call this a "URL". URLs are used 'out on the web'. Inside the server you do not have URLs, only paths and files.
Another gem of a resource from the vault! Thanks a lot, never ceases to amaze me the variety of useful info I can find on here and the amount of time it saves me in trying to explain some of these things to clients, friends, etc. :)
Great post, i love the happy face to show the effect on visitiors.
Now i just have to break the news that it is only going to take days... not just mins to get this sorted out :)
Very nice Jen :)
Really like posts like this that are clear and concise, not to mention the graphics. You know what they say about a picture being worth 1000 words...
Great info :)
I'm not sure if I agree with the way Step 2 is explained under 301 Redirect Process. I was under the impression that you send a request to the original URL, you receive the 301 redirect as a response from the server, and your browser then sends another request to the new URL, receiving the new page as a response.
Maybe that was the point you were getting at or perhaps I'm mistaken. Just thought I would mention it for clarfication/discussion.
Thanks for the clarification! Yes, I should have mentioned that the server is what sends the 301 redirect as a response. I'll update that to make it a bit more clear.
Yes, if you google for "http status code checker" the tool at seoconsultants.com will show the entire process. Very useful for checking your 404's and other things.
In fact I just noticed that we're returning a 301, then a 302, then a 200 on our major category pages - blehhh such a horrible CMS lol.
Ok
Do i need to use a url rewrite or can i get away with just the 301.
Will google still pick up and boost rankings for 301ing a page to a new keyword rich page name oposed to the original page having a non keyword rich page name by just using a 301 without url rewrite?
Also anyone out there on iis shared hosting using html know how to 301 all versions of the homepage to one single version without getting a loop?
I have a question:
Say you have the following two URLs:
www.example.com/myfolder/
and
www.example.com/myfolder/index.html
Obviously, both are serving the same page but Google is treating the 2 URLs as 2 different pages with www.example.com/myfolder/ with a higher page rank.
So you'd want to merge the 2 URLs, by doing a 301 redirect from www.example.com/myfolder/index.html to www.example.com/myfolder/
Only problem is, /myfolder/ does a redirect to /myfolder/index.html only it doesn't show this in the address bar. Doing a 301 redirect of /index.html back to /myfolder/ causes an infinite loop.
What should be done in this scenario? Do an URL rewrite of /index.html to /myfolder/? Would that carry over the same SEO benefits than a 301 redirect?
Thank you!
Actually, I think I answered my own question. Please ignore.
Thanks for detailed diagrams, it makes a lot more sense now.
Excellent post, Jen! Very understandable and short, so you don't get confused :)
Thanks!
Thanks Jen, As you said it's difficult to wrap around but this is a very simple explanation of HOW the redirects and URL rewrites work!
Thanks again!
~Dubs
Oh my God ... Thenks Jennita :)Seems like you get into my head to URLRewrite portion .. and answered the questins their :DTha main question I was looking for an answer of is:If I wanted to make my URL's SEO freindly using URL Rewrite, is it going to redirect the requests using 301 header or will do something like URL masking?Now it is clear to me .. Both options are there, I have to do it the way I want for purpose I need.Still I need to read more about it even testing and implementation will give better understanding. Thanks again for the too valuable post :)
Great read. So if I understand this process a 301 is the same as pointing . Right ?
very good post.
I prefer the URL rewrite because
1)it bypasses the additional "internet travel time" that is needed before preparing the new http request of the 301 redirect
2)because it keeps the internal structure of urls secret
but in case m not allowed to use the rewrite rule (the fake, transparent, and server-side redirect), I will not be so sad especially taht 301 is an SEO method as every SE says
If you are switching to keyword-friendly URLs and have properly deployed 301 redirects on all the old URLs, what's the best approach for changing the internal links on your site?
Should you immediately start linking to the new keyword-friendly urls everywhere, or should retain the links to the old URLs for a certain amount of time?
Is there any joomla component or module that manages the redirects automatically. All my pages are loading with the www and non-www version.
I am having a ridiculously difficult time getting an Apache Rewrite rule to function as intended. Wondering if anybody could help me spot the error.
I am trying to rewrite a parked domain to a subfolder on the primary domain without changing the browser address bar url.
RewriteCond %{HTTP_HOST} ^domain-name\.com$ [NC]
RewriteRule ^/?$ /domain-name [L]
I can get the domain to permanently redirect, changing the address bar in the process, but that is not the objective. The rewrite is supposed to function in the same manner as a "pretty permalink" style redirect, such as the way it works when rewriting an SEO pseudo directory structure to a query string url.
What do I need to do to fix this?
hi
great aticle.... i m using Apache tomcat and Apache server though m new to both of thesei Have a war file deployed in webapps of tomcat which m accessing using apache servernow wat i want is to convert a url which looks likehttps://localhost/abc/xyz/page1.htmtohttps://localhost/xyz/page1.htmi tried using .htaccess file but i m very much confused about wat to write n where to place .htaccess file....please help....
Hi,
Grate article.Really i was searching like this type articles.I think my searching comes to end.Actually my website is https://www.elivepages.com and i want to redirect into a new domain.But i am affried for my recent rankings.by the way i hope i can save my ranking.
Can someone clarify for me the difference between a URL rewrite and a web forwarding domain? I've never heard of the former but it sounds like it acts like the latter.
I'm trying to decide if, with our site redesign, we should move several long-standing pages up a level to have a shorter, more user-friendly url. But I'm scared of losing all the links and traffic we've accumulated for those pages.Will a 301 redirect prevent that from happening? If so would I move the page and put the 301 on the old url? Or the other way around?
I'll be happy for any insight anyone has to share to help me make this decision!
I used to use mod rewrite extensively, but as my rules started becoming more and more complex, and much more dynamic, I found it easier and more efficient to just re-route all requests to a php script that figures it out from there. This way I can access dynamic urls stored in a database without having to mess with apache. Just make sure to enable existing files and folders if you want to. I often use this:
# send everything to the front controller
# if it isn't in the js, images, or includes folder
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(js|images|includes)/?$ front-controller.php [NC,L]
I tried this 301 redirect today. It's work for me even in dynamic pages.
redirect 301 /old/old.htm https://www.you.com/new.htm
I get a 301 redirect message when i ask google to fetch/crawl my site. is this message preventing my site from being indexed?
Nice explanation. What's your view on reversing a 301 redirect? Any potential problems with indexing and ranking the original domain ?
Slightly confused, so is the article saying this is a two step process or that these are two different items? I would imagine this would cause an infinite loop, for example:
I have https://www.site/com/contact.htm that i rewrite as https://www.site.com/contact
Then if i was to make a 301 for contact.htm to /contact wouldn't that just never resolve?
i am getting huge confusion with 301 redirection i have placed following code in my website using .htaccess
ErrorDocument 404 https://www.jiwantamang.com.np/404.php
RewriteEngine On RewriteCond %{HTTP_HOST} !^jiwantamang\.com.np
RewriteRule (.*) https://jiwantamang.com.np/ [R=301,L]
But in Google webmaster tool using above code i cannot make complete fetch as the result comes as redirected. and url are not submitted to index in search engine and when i remove above code from .htaccess and try for fetch as Google than fetch as Google is completed so kindly share your knowledge to know more about it..
Do you please help me rewrite this URL
Thank you for the article Jennita. I run a startup where we build better websites for doctors and clinics. All of these "sites" are not actual sites but basically profiles hosted on our own site, but each one has multiple tabs, contact form, appointment scheduling, etc. (everything their old site had and more)
Recently I have been considering building these profiles for free for different clinics and only requesting that we set up a 301 redirect from their original site to the profile we have built for them. Theoretically, would all of the SEO juice come to my startups website? If, let's say, we got 30 different clinics original URLs to 301 redirect to our site, wouldn't that be great for SEO purposes?
Appreciate the tips.
Really a nice and simple explanation - and I am even not a developer and still get it ;-) Thanks! Twittered as well.
its good to understand http and what your webserver is doing
ahh i lost points now i got nofollow again lame...
Hi,
I have checked certain domains are seamlessly accessed by putting two different url, i.e., you prefix www and don't prefix www, how they are landing to the same domain?
Hi everyone.
Just for example.
I wrote this rule on my .htaccess:
RewriteRule ^articles/([^/]+)/([^/]+).php /articles.php?lang=$1&art=$2
How can I redirect dinamic address to static address?
I tried to put flags [R=301,L] but it redirects to dinamic address.
Thank you
I'm still having troubles understanding this. Basically, I have a wordpress site and some urls that were constructed several years ago are now considered spammy. However, since they are a few years old they have several thousand links pointed at them. How do I retain the link juice while making the URL's google friendly?
Thank you!
Make sure that you set up 301 redirects from the old URLs to the new URLs, that will conserve at least some of the link juice.
I have an other kind of question. We have a webshop and we are opening a second one. 500 products of our firts webshop are going to be migrated into the second one.
The segmentation in both shops is different. We are redirecting using a IIRF tool. If we redirect each URL separately the IIRF tool is getting quit big.
Now are programmer asked if it is okay to first redirect form the first to the second webshop and than, in the second webshop another redirect to the proper url. This is a difference of 500 IIRF lines.
But i really have no idea if this is a bad idea and if it wil effect the rankings.
Thanks!
Thanks Jennita. I have a question if that is ok.
I have a prestashop store and have just set up a second language. As a result all URLs get a /en/ folder added on for english language, and a /it/ for Italian language. Obviously these are necessary to distinguish the same page in two languages. However, as the english site has already been around a while and has pagerank and links, I would like to remove the /en/. Should I use redirectmatch or rewrite?
For example, the home page:
Current page - https://thecoffeelocator.com/market/en/
Desired url - https://thecoffeelocator.com/market/
I need to do this for ALL Urls within the site.
@Jennita
It's quite interesting. I'm quite late to add comment on this post. But, Today - I was searching about 301 on SEOmoz and come to know about this blog post. I have very complicated question about redirect.
Honestly, I did not want to ask my question in comment because, Q & A section is best place to get it done. But, why should I not add my question on right circle of commenters... what you think ??
I have redirected following 3 domains to new website...
https://www.lampslightingandmore.com/ To https://www.vistastores.com/table-lamps
https://www.vistapatioumbrellas.com/ To https://www.vistastores.com/patio-umbrellas
https://www.spiderofficechairs.com/ To https://www.vistastores.com/office-chairs
I have done it before 3 months but, Google still shows me home page URL in search result rather than new landing page. You can check following search results to know more about it.
For LampsLightingandMore ~ On second or third page:::
For VistaPatioUmbrellas ~ On second or third page:::
For SpiderOfficeChairs ~ On Second or third page:::
I have hosting with godaddy.com i am trying to do 301 redirect on my site Toronto airport taxi ( https://www.airporttaxigta.com ) my hosting is on windows server and .htaccess file is not supported and the asp code is not working please help i don’t want to change hosting. Please can you tell me how can i find out if my 301 redirect is working properly.
This is an older post and you may not get a lot of response. If the links in the post don't give you the information, consider getting a free Pro trial and asking in the Q&A section at https://www.seomoz.org/q. Thanks!
Bookmarked. I have tried and failed to explain this too many times.
I'm currently using Ionics Isapi Rewrite Filter
h
h?
I have seen short concise comments before. Now if I only understood exactly how you meant it. Is it the "h" of hearty agreement or the abbreviated laugh kind of h?
@jennita, nice post. Clear easy to follow information. I'm using this one. Thanks
This is crucial to understand, especially when redesigning a site or doing major architectural changes. I often find the biggest challenge is identifying all the pages/urls on a site that might change. There are often orphan pages that are long forgotten, but may have inbound links or get small amounts of traffic. Looking at analytics and Yahoo Site Explorer helps identify them, but it can be a daunting task on large sites that haven't been changed in years...
I have a question, what happens if the old URL has been demoted to the supplemental index?
Here is the issue we are facing:
New URL doesn't rank as high as we'd like and has PR0, old URL doesn't show up in the main index anymore but has a PR of 3. If we 301ed the old to the new will the new URL in turn inherit PR even though it's not in the main index anymore?
Would it be necessary to explicitly declare the old url in our sitemap.xml in order for google to take notice of it (and in turn redirect it passing juice)?
How long ago was the redirect added?
Wait at least six months to see the full PR effect in the Google Toolbar.
I was looking for any useful matter about 301 redirect by passed two days and now my search ends here.
it was really very helpful for me.
Thanks a ton!
This is a great article! Thanks for the excellent illustrations.
What I would like to see is a diagram (of a similar nature) that illustrate a 302 Temporary redirect and why it's not so good for SEO.
The 301 and 302 redirect both cause the browser to issue a new request for a new URL.
The only difference is that the HTTP header says "302" instead of "301". Likewise for "307".
The flow diagram would be the same for all of these.
Excellent post! 301 re-directs are not as simple as they seem. In my case, I use Joomla! for most of my sites and it could get tricky at times. Do you have any suggestions for Joomla! users?
I do, get Drupal.
Joomla! is chock full of Duplicate Content issues.
There are more than a dozen different URLs that will return your Home Page content for example.
I knew about this, but didn't know all the details. This post was a great help. Thanks!
I am passing this to any developer I run into that just dont get it!
Thanks for the visuals!
I do wonder if you end up with 100% of the links?
I don't believe you would end up with 100% of value of the links when you're using 301 redirects. I think the real value is long-term because you get some of the value from those links and in the future, any value from links pointing directly to the new domain.
Agreed I don't believe you get 100% of the link juice, but the alternative is to get 0% of the link juice. :)
I have been having trouble with 301's. The hosting company I use makes it easy to redirect, but my clients hosting company doesn't have that feature. Now I have to insert the php script into the old page to have a redirect to the new page. Not sure which is the best method in the php world.
VBP,
301's are pretty common server functions. It the issue with the clients Content Management System, Hosting Company Solution or maybe is it a Windows Server that handles 301 redirects differently from the server that you use? Just curious.
The client's host doesn't allow them access to the .htaccess file?
I assume they use IIS and the hosts have everything locked down so that users cannot alter the configuration. If you can do so, change hosts and/or move to Apache and get some control back into how your sites are configured.
Brilliant graphics. This one goes on the wall. Thanks!
Nice one chaps, very useful
Nice write-up - I'm continually amazed that clients miss something so basic as proper redirects.
I love using them to move content to new domains. Helps when an underperforming blog needs to have it's content and traffic moved to a better performing site.
Helpful post, thank you.
However I'm still having trouble using mod_rewrite to acheive 301 redirects (to ensure all old URLs get redirected the new ones before being rewritten internally back to the old query string format)
I'm trying to redirect from this:
/?showCategory&categoryId=5
.. to this:
/handbags
..using this:
RewriteRule ^(.*)categoryId=5(.*)$ /handbags$2 [L,R=301]
..or this:
RewriteRule ^(.*)categoryId=5(.*)$ domain.com/handbags$2 [L,R=301]
But that doesn't work.Similarly this causes an inifinate loop:
RewriteCond %{QUERY_STRING} .*categoryId=5.*$RewriteRule ^.*$ /handbags
Can anyone provide the answer?
All the internal rewritesare working fine, and some redirects are too, such as
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.php(.*)\HTTPRewriteRule ^(.*)index\.php$ /$1 [L,R=301,QSA]
...which is a useful way of avoiding having two home pages (domain.com/ and domain.com/index.php).
Ok so I'm getting somewhere:
To avid the infinite loop we must use the THE_REQUEST, because we knoe THE_REQUEST is going to be the initial request and not the internal re-write.
So continuing the previous example, I now have this:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /.*categoryId=5.*\ HTTP/
RewriteRule ^.*$ https://www.domain.com/handbags [L,R=301]
...which almost works. Except I am getting the old query string URL appended ontot he end of the new URL:
https://www.domain.com/handbags?action=showCategory&categoryId=5
But I'm not using the QSA flag nor am I using back links.
So I'm still after some advice if anyone knows the answer...
...So I have discovered that putting a question mark at the end of the target URL prevents the query string from being appended at the end:This one works for me, hope it does for you too:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /.*categoryCode=30.*\ HTTP/
RewriteRule ^.*$ https://www.domain.com/handbags? [L,R=301]
The downsides are:
1. I have to include the https://www.domain.com otherwise I get the file path
2. If I need to include some additionalquery string at the end of the new URL I may have trouble.
Add my thanks- I hadn't seen the rewrite and redirect together before like this.
Wirh the task of redirecting our old site's pages to a brand new site, this post gave me a good image of the entire process.
Thumbs up
*** Sure, you know that rewriting a URL means that the URL displayed in the browser changes to be more SEO (and user) friendly. ***
I find this wording to be confusing. A rewrite does not 'make' a URL. It does not change anything in the browser. URLs are defined by the URLs in the links in the pages. So, if you want users to see and use new URLs, it is those URLs that you have to use in the links in the page.
Likewise a rewrite does not connect a URL with another URL, it takes an incoming URL request from the web, and internally changes the path part to a different value and fetches the content from there without revealing what that new internal path is.
Original description:
URL Rewrite Process:
User lands on new SEO'd URL
Using mod_rewrite, ISAPI_Rewrite, etc. new URL points to old URL on the server
Server calls the code from the old URL
Page is displayed in browser, displaying the new URL
Corrected description:
URL Rewrite Process:
User clicks on link pointing to new friendly URL.
URL request arrives at server and is passed to handler.
Using mod_rewrite, ISAPI_Rewrite, etc. path part from the new URL is internally modified to point to old internal path.
Server calls the code from the old internal server path.
Page is displayed in browser, displaying at the same URL the user requested.
Original description:
301 Redirect Process:
User lands on original URL
Using code, mode_rewrite, etc. the 301 redirects URL to the new one, literally changing the URL that is displayed in the browser from the old to the new
URL Rewrite process begins again
Corrected description:
301 Redirect Process:
User requests old URL from server (from bookmarks, old SE listing, whatever).
Using mod_rewrite, PHP code, etc. the server sends a 301 response header back to browser with a reference to the new URL.
User requests new URL on server.
Server receives the request and serves the content (either directly, or through a further rewrite).
Redirects should be listed before Rewrites in the .htaccess file, and all should use code from the same Apache module.
Thumbs-up to Jen for bringing up this topic. Thumbs-up to G1SMD for setting the records straight. Unfortunately, I couldn't express that with the comment's voting buttons, although I thought I was on SEOmoz at this time.
hi, i recently rewrited my site urls https://www.websitename.com/questions...php?cat=Actuat to https://www.websitename.com/Actuateal...ndanswers.html now problem is google showing still old url in search results and if click on the old link newurl is not displayed..it is only showing old url i.e same page is accessble from 2 urls i want to display only one url that is new url , how can i? THanks in advance
You also need to set up a 301 redirect from the old URL to the new URL. This will redirect the engines as well as users to the new, current page.
any easy way of redirecting? i have 300 pages to be redirected
Depending on the site, normally you can use regular expressions to set up the redirects.
Check out this great post for more info: Using mod_rewrite to Convert Dynamic URLs to SEO Friendly URLs
soori, keep in mind that you HAVE TO (not just want) to solve that problem (jennita said you how) because of duplicated content issues. This sould be a "high priority" task for you.
Agreed, this is a top priority.
Not sure this was covered... sorry if I duplicate it. If this post is not in the right area, again I apologize... I had to change the domain name to a new one, with the old domain having to now display a 404 error, after a period where I had the old one 301 redirect to the new. The old domain name, now currently provides a not found error, which is what I want. However my Google sitemaps still show a number of links under the old domain name, which I would like to get removed.They have been there for months, and currently remain there with the latest crawl of yesterday. I understand that having several search engines still indexing the old domain name, might be the problem? Using "site:" preceding the domain name, brings up almost 90 pages on Yahoo and 20 on Google where the old domain is still shown. Does this mean that I need to have all of these changed, or is there some 301 redirect that will accomplish the changeover, without having to have all of these changed?
Ok I'm a little stumped. We had to move our blog and blow out our content (dont ask) and start completely fresh.We set up a 301 to the new blog which basically went something like this. www.oursite.com/blog to https://blog.oursite.com
So we 301 /blog/ to new blog address and it works if you go to the old blog URL. However, google is still showing a 404 for all the hundreds of pages that were on the old blog.
How do we get Google to understand anything in that entire folder is gone?Thank you in advance.
Good one really was very helpful to freshers like me. Also i use 301 redirect checker to confirm the same.
Nice Article. It would have been much easier, if you have explained with an example.
Thanks for this post Jen, Wicked helpful and a great discussion. The links are particularly useful. Also LOVE the idea of redirecting up to the category level for archiving.
Sebastien's point is something I'm considering now - sending an old site to a new site by having the 404s check against a db for new urls before they load. Good to know it's on the up-and-up.
Thanks for this post. It came at the perfect time, since we are working on converting a small dynamic site to have seo friendly urls.
I had thought that a mod_rewrite would create duplicate content issues, but I guess the 301 takes care of this.
The redirect causes the client to request a different URL.
Content is no longer served at the old URL.
The URL that returns "200 OK" is the one that will be indexed.
Nice explanation of Redirects and how they work. Every SEO needs to know this stuff. It should be in the training package :)
Great article! Thanks Jen. Does anyone know how to use 301 redirects that do not bypass the 404 error? I like to use custom 404 messages but I want to use 301 redirects to avoid Canonical Issues. Thanks!
When a request hits the server it can respond with a "200 OK" response and content, or with a "404 Not Found" response and an optional error message, OR with a redirect response code that tells the browser to make a completely new request for a different URL.
In light of that, your question doesn't make a lot of sense. The server either redirects, or serves content, or sends an error. If the response was a redirect, then the new request to the server will either get back another redirect, or content, or an error.
You craft your rules and scripts so that the appropriate response is returned for any URL request that could be asked of your server. The devil is in the detail.
In most servers, URL handling to generate redirects occurs way before file handling to return content (or an error if there's no file), that is, unless you rewrite incoming requests to a script. In that case, it is the script that needs to analyse what the requested URL was and decide what sort of header to return. If it is a redirect or an error then that header must be returned before any HTML code is sent.
Thank you for such an in-depth response! I am very new to this technical kind of SEO, so I ask a lot of strange questions. What I have is a .htaccess file that redirect https://mydomain to https://www.mydomain.com like this:
RewriteEngine OnRewriteCond %{HTTP_HOST} ^domain\.com [NC]RewriteRule (.*) https://www.domain.com/$1 [L,R=301]
But when I use this code, if someone types in www.domain.com/blahh, they get redirected to www.domain.com instead of being told that the page doesn't exist. So what I have been trying to figure out is how to redirect from the non-www to the www in the domain - but keep the custom 404 message.
After the first request is redirected and the browser makes a new request for the new URL, is it then served with the 404 status code in the HTTP header in response to that second request?
If it is, then that should be fine.
You can check that using the Live HTTP Headers extension for Firefox for example.
If the second request returns "200 OK", for non-valid URLs, then there is a big problem.
@mblum3: In other words, if your server sends status code 404 and always the same content (for different non-existing URLs) you're still ok with duplicated content because you've told to the spiders that this URL not exist. In that case they're not carryng anymore which content will you serve for this URL because they don't need this URL to be indexed or spidered.
Thanks to everyone for all your wonderful comments! I'm glad to have helped a few people understand the process. And it's great to see the SEOmoz community step in and answer each other's questions. :)
I also appreciate the fact that not everyone agrees with the descriptions or terminology used. My focus was to give non-technical people a good overview of the process of how rewrites and redirects work together. Of course this could have been said using different terminology and we could have gotten extremely technical, but this will be for another post. :)
I don't think that I got 'any more technical' here, but I do think it is absolutely imperative to differentiate a URL that is 'used out on the web' from a 'file path' used internally in the server.
In fact, the difference between these two things is crucial to the understanding of this stuff.
Links on pages are what define URLs. A URL is seen to 'exist' as soon as you create a link on a page with something in the 'href' part of it. It is that entry that is stored in a SE links database.
Only when that link is clicked by a user, or when the SE bot requests that URL directly, and the request hits the server, do we actually get to find out whether it returns 200, 301, 302, 307, 403, 404, 503, or some other status code within the HTTP Header. If the URL is blocked by robots.txt the status will forever remain unknown to the bot. That's because it will not be able to send that URL request to the server.
Only a URL returning '200 OK' will be indexed with content. Other status codes will force the bot to do other things.
A redirect tells the browser requesting the old URL to make a new request for a new URL.
A rewrite connects an external URL request with an internal filepath/file; one that is different to that initially suggested by the path part of the original URL request, without revealing what the internal path and file actually are.
So a Redirect is: URL --> URL.
And a Rewrite is: URL --> File.
That is, the term 'URL' has no meaning inside a server. A server deals only in physical paths and filenames. The job of the server software is to translate incoming URL requests to internal paths and filenames.
Can anyone recommend a redirect that would work in a LAMP enviornment (htaccess) that will allow me to remove the trailing slash from a directory?
I have my blog setup at https://www.danfinney.com/blog The server adds the trailing slash making it https://www.danfinney.com/blog/ but the software that I use (Drupal) sets the base path without the trailing slash which earns me a warning in Webmaster Tools. Any help would be appreciated!
The canonical URL for a physical folder does have the trailing slash. The redirect is correct. You should be linking to the URL with the trailing slash here.
There are several ways to override that, but why fight the HTTP specs?
When drupal puts the base path into the XML RSS feed it leaves off the trailing slash. This is causing a warning in Webmaster Tools. I think you are suggestion drupal needs to resolve a correct url instead of using a 301 redirect in this instance?
Good article, but I've run into so many problems with 301 redirects and .htaccess files depending on what type of server, and (more recently) what to do within the different content management systems out there like Drupal, WordPress, among other factors, that it would be nice to have a "to-do list" or a instructions for all the various scenarios.
Great idea! Thanks :)
Great informations
very Nice