Overview
Recently, I came to know about the new function of Response
named as Response.RedirectPermanent
. So what is Response.RedirectPermanent
? Where to use it? It's the same like Response.Redirect()
function as it redirects you from one page to another but it returns HTTP status code 301 as compared to HTTP 302 returned by response.redirect()
. So, in this article, we would have a brief overview of Response.RedirectPermanent
.
Response.RedirectPermanent
Consider a following scenario: We have a web application which sells products to end users. In order to increase the user count or to bring more users to the website, the company decides to start with discounts on certain products. Hence, it introduces the new page named as Discount.aspx listing all the products which has discounts on them. When user clicks on any of the discounted products, website redirects the user to page named as Products.aspx where user can view the details of product. In order to increase the revenue, company hires the SEO and registers the page on different search engines like Google, Yahoo, etc. Hence, discount page gets registered on different search engines.
Now, after some months, the company decides that it don't want to give discounts on the products and thinks of removing the page. But they don't want to lose their customers who were coming to their site through the discounted page.
In this case, we have two options:
Disadvantage: When search engines see the same data on both discounted and products page, they can penalize the site for having the duplicate content and would delist the site.
Disadvantage: When we use response.redirect
, then it returns the status code as HTTP 302 temporarily redirected to different search engines. So, search engines store this information in their table that this discounted page had returned status code HTTP 302 and it was temporary re-directed.
- Copying the content of products page to discounted page
- Use Response.Redirect: We can use
Response.Redirect
on the page load of discounted page which would redirect the user to products page.
Search engines expect that the next time when we would hit the discounted page, it would show the data and shouldn't return 302 status code. If next time again, page returns status code 302 then search engine penalizes the site and would delist the site. Hence, in this scenario, we should always use Response.RedirectPermanent
. What does Response.RedirectPermanent
do?
When we use Response.RedirectPermanent
, then it returns status code HTTP 301 Moved Permanently. It tells different search engines this page has permanently moved to new page. By this, different search engines update their index with a new page. So, the next time if someone clicks on the discounted page, user would be automatically directed to products page by search engines. So, let's build a small application, which would have two buttons - one button would use Response.Redirect
and the other button would use Response.RedirectPermanent
. We can view the GET
request details by using the tool named as HTTPDebugger
. Below are the GET
requests. You can see that when we use Response.Redirect
, then browser has returned status code as 302 Found; however in case of Response.RedirectPermanent
, status code returned is 301 Moved Permanently.
Below is the screenshot:
Conclusion
Whenever we want to remove any page from website, we should always use Response.RedirectPermanent
. With this, we wouldn't lose our customers directed to our site through different search engines. Hope with this article, you got a brief overview of Response.RedirectPermanent
.