There are times when we need to move to a different location, for various reasons (e.g. college, work, etc.). We would either move temporarily or permanently, depending on our goals. Either way, we need to announce to institutions or friends that they can find us on a different locaton, because they will have hard time locating us if we don't leave a note.
The same principle applies to websites. Users might find an old location of a piece of content we recently moved through Google, Yahoo or other search engine, which they would like to read, and unless we notify them, or redirect them to the new location automatically, they won't be able to find it.
There are 2 types of redirects, which are made for various reasons (e.g. switching to a different hosting service, rebranding, aesthetic desire to beautify URLs, etc.):
There are many languages in which websites are built, meaning that there are many ways how to inform users. You, as a website owner or manager need to notify users where the content was moved, by redirecting them to the new URL, in the exact language.
The aim of the solutions below is to assist you notify the users in the right language your website is built in.
Note: It's highly important to create a forwarding address every time you decide to switch to a new host or service, because the changes you make won't be detected by site-ranking metrics, i.e., your new content won't get the attention of the spiders (i.e. the inspectors which check the quality of the content and offer it to the public), as they will be crawling in the room you used to live and which is now empty.
If you're using PHP, you can just add this to the top of your script:
header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
header('Status: 301 Moved Permanently');
header('Location: http://www.yoursite.com/new-rss-feed');
exit();
To apply the redirect and register the change, you can employ .htaccess to redirect requests from the old feed to the new one.
Feel free to check this article on askapache, where you will learn how to make this adjustment.
Once the redirect is saved, the rules you created can be found into the web.config file, which you can edit whenever you want.
The RapidTables redirect code generator is very simple to use and it supports web pages redirection of html, php, asp, aspx files and .htaccess redirect. All you need to do is enter URL of old page, then the URL of the new page, then select the redirect type and hit the Generate Code button. Alfer that, you need to copy the generated code and that's it!
You may try this tool on their website:
https://www.rapidtables.com/web/tools/redirect-generator.html
This Domain to Domain 301 Redirect Generator for htaccess is simple to use and can help you apply 301 redirects easily.
You can try it on the developer's website:
Feel free to enter the following code in the page:
wp_redirect( "http://www.my-website.com/a-new-destination", 301 );
The documentation on the developer's website should help you apply redirects properly. Alternatively, you can always consult experts on forums.
You can create a temporary redirect in Nginx, by adding a line like this to the server block entry in the server configuration file:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation redirect;
If you want to apply a redirect, you can use mod_redirect with the following syntax:
$HTTP[”host”] =~ “^domain\.org” {
url.redirect = (
”^/(.*)$” => “http://www.domain.org/$1″
)
}
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*\.html)$
RewriteRule (.*) http://www.example.com/forums/$1? [R=301,L]
<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.new-url.com/” );
response.setHeader( “Connection”, “close” );
%>
or
// Redirect 301.
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", newUrl);
class YourView(View):
def get(self, request):
redirect("http://newdomain.com/")
redirect_to "http://host.com/foo/foo_slug", :status => 301
or use open-uri handles, which redirects automatically:
require 'open-uri'
response = open('http://***/xyz')
You can create a permanent redirect in Nginx, by adding a line like this to the server block entry in the server configuration file:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation permanent;
To apply a redirect to your feed, follow the steps below:
This simple-to-use plugin will help you apply redirects in a much easier way. You can find it and install it via the URL below:
The RSS Redirect & Feedburner Alternative plugin is a better way to apply feed redirects, with a few clicks.
You can find more info and install the plugin, via the URL below:
https://wordpress.org/plugins/feedburner-alternative-and-rss-redirect/
To apply a temporary redirect, enter the following code:
// Temporary Redirect (Redirect 302)
response.sendRedirect(newURL);
To apply a temporary redirect, add the following line in the .htaccess file:
Redirect /product.php http://www.xyz.com/promo.php
The video below offers an insightful way for you to apply redirects:
Entering the following sequence in .htaccess with help you apply a 302 redirect:
Redirect 302 /pageA.html http://pageB.com/new.html
Alternatively, you can append the following rule:
RewriteEngine On
RewriteRule ^pageA.html http://pageB.com/new.html [R=302,L]
To make a permanent (301) redirect in PHP, enter the code below, at the very top of the document:
<?php // Permanent 301 Redirect via PHP
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://websiteurl.com/new/url/");
exit();
?>
The code below is all you need to enter, to apply a 302 temporary redirect:
<?php
header("Location: http://www.websiteurl.com/other-temp-url/index.html");
exit();
?>
To apply a permanent redirect in Python, the URL is all you need to enter:
server {
listen 80;
listen 443 ssl;
server_name invalid-domain.com;
return 301 $scheme://valid-domain.com$request_uri;
}
Enter the URL below, in routes.rb:
get '/old/path', to: redirect('/new/path', status: 302)
The following article will show you how to successfully apply redirects:
https://ecom-support.lightspeedhq.com/hc/en-us/articles/220319928-Setting-up-redirects
If you don’t receive the email in the next 2 minutes please check your junk folder, and add [email protected] to your safe sender list.