301 and 302 redirect
When you remove a page or product from your website, it gives No-Page-Found error for that URL because that URL is gone. The server will fetch 404 error (No page found) to the visitors and it will increase the bounce rate as well as negative impact of the ranking of your website on Google and other search engines.
Now, there are two redirects for a gone page.
301 redirects - This is permanent redirection of a gone page to a new URL which is in force.
302 redirects - This is temporary redirection of a gone page to a new URL until the same (gone page) is redesigned or redeveloped. It is generally used in maintenance mode.
1. 301 redirection using .htaccess apache server (use the following code)
Redirect 301 /old-url.html http://www.mydomain.com/new-url.html
2. 301 redirection using php (use the following code)
<?php
// PHP permanent URL redirect - generated by www.rapidtables.com
header("Location: http://www.mydomain.com/new-url.html", true, 301);
exit();
?>
1. 301 redirection using .htaccess apache server (use the following code)
Redirect 301 /old-url.html http://www.mydomain.com/new-url.html
2. 301 redirection using php (use the following code)
<?php
// PHP permanent URL redirect - generated by www.rapidtables.com
header("Location: http://www.mydomain.com/new-url.html", true, 301);
exit();
?>
3. 301 redirection using html (use the following code)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.mydomain.com/new-url.html">
</head>
<body>
</body>
4. 301 redirection using ASP.NET (use the following code)
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.mydomain.com/new-url.html");
Response.End();
}
</script>
5. 301 redirection using ASP redirect (use the following code)
<%@ Language="VBScript" %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.mydomain.com/new-url.html"
Response.End
%>
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
302 redirection
1. using .htaccess apache (use the following code)
Redirect 302 / http://www.mydomain.com/new-url.html
2. using php (use the following code)
<?php
header("Location: http://www.mydomain.com/new-url.html");
exit();
?>
3. using HTML meta tag (use the following code)
<meta http-equiv="refresh" content="0;url=http://www.mydomain.com/new-url.html">
4. using Java Script (use the following code)
<script type="text/javascript">
window.location.replace("http://www.mydomain.com/new-url.html");
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.mydomain.com/new-url.html">
</head>
<body>
</body>
4. 301 redirection using ASP.NET (use the following code)
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.mydomain.com/new-url.html");
Response.End();
}
</script>
5. 301 redirection using ASP redirect (use the following code)
<%@ Language="VBScript" %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.mydomain.com/new-url.html"
Response.End
%>
--------------------------------------------------------------------------------------------
HTTP status codes
| Status code | Status code name | Description |
|---|---|---|
| 200 | OK | successful HTTP request |
| 300 | Multiple Choices | |
| 301 | Moved Permanently | permanent URL redirection |
| 302 | Found | temporary URL redirection |
| 303 | See Other | |
| 304 | Not Modified | |
| 305 | Use Proxy | |
| 307 | Temporary Redirect | |
| 404 | Not Found | URL not found |
302 redirection
1. using .htaccess apache (use the following code)
Redirect 302 / http://www.mydomain.com/new-url.html
2. using php (use the following code)
<?php
header("Location: http://www.mydomain.com/new-url.html");
exit();
?>
3. using HTML meta tag (use the following code)
<meta http-equiv="refresh" content="0;url=http://www.mydomain.com/new-url.html">
4. using Java Script (use the following code)
<script type="text/javascript">
window.location.replace("http://www.mydomain.com/new-url.html");
</script>
=============================================================
No comments