How to Redirect a URL: A Comprehensive Guide

COPIED!

Learn the step-by-step process of URL redirection, its significance, and how it can help enhance your website's SEO. Read our blog post now.

white and black One Way-printed road signages

When you create your website, everything seems to unfold by itself. You have a very nice page and everything is perfect.
Over time, to your regret, the administration of your page becomes more complex, the things that seemed more comfortable to operate now become complicated.
It is likely that your site has grown and now you need to upgrade your hosting plan, now you have more posts, files, more traffic and URLs, and with it comes chaos.

Having more traffic is great for your website, of course, but creating additional pages, posts and URL structure is not so easy.
It could be that you stop offering some service, or you want to change the structure of your web page, or that you want to change your domain name, for which you now need to make a redirect (or several).

What is a redirect?

Redirecting is pointing one web page or URL to another.
Every time someone enters a URL that they no longer want to use, they are taken to a new page or another address

There are several types of redirects, and several other ways to do those redirects. Here are the most popular:

Redirect types

301 Redirect

The 301 redirect is the most used. This redirection is permanent, and it is very important because it transfers all the "importance" from one URL to another. Search engines will recognize this redirection and your old URL will disappear, giving priority to the new URL.

301 redirect with PHP

header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.example.com/'); exit();

301 redirect with .htaccess

# Redirect the entire website to another domain or URL Redirect 301 / https://newdomain.com/  # You can also do this by specifying your old domain: RewriteEngine on RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com$ rewriterule ^(.*)$ https://www.yournewdomain.com [R=301,L]

Redirect http to https

RewriteEngine On RewriteRule ^.well-known/ - [L,NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

302 Redirect

This is a temporary redirect. It is used, for example, when you are setting up a new web page, and you go to a page that says "We are under construction, you will soon be able to access our new page".

# Temporarily redirect the entire website to another domain or URL Redirect 301 / https://newtemporarydomain.com/

Meta Refresh Redirect

It is not very popular, but it is very easy to do. Just include the following code inside the <head> of the web page you want to redirect:

<meta http-equiv="Refresh" content="0; url=http://www.mynewdomain.com/" />

JavaScript Redirect

It is also very simple, you just have to put the following in the JavaScript to execute:

window.location.replace('https://www.example.com/')

6 Reasons to do a redirect

1. You changed your domain

If for some reason you had to change your domain, it is necessary to do a redirection from the old domain to the new one.

2. You went from http to https

You purchased an SSL Certificate and now you need your visitors to sign in with https.

3. You have many domains and you want to have only one

You registered multiple domains under your business name, but only want to have one primary domain.

4. You have very long or complicated URLs

If your addresses are of the type http://www.mydomain.com/products/product-category/my-spectacular-product-that-no-one-else-sells-it.html, and you want them to be https://www.mydomain.com/my-product. Yes dear friend, you need a redirect.

5. You need to redirect one page to another

If your blog was installed on blog.yourdomain.com, but you want it to be www.yourdomain.com/blog

6. You are creating a new web page and don't want visitors to see it yet

Well, we don't have much to say at this point, we already said it all in the title.

Conclusion

You can always use the above methods to perform a redirect. We hope your website grows and improvesimplementing the redirects you learned about in this post.

SEO
About the Author
gray and white robot illustration

Editorial Crew

Content

We are the WinkHosting Team! Somos el equipo WinkHosting!

You Might Also Like

Ready to create Something Great?
Start today. From $14.75 USD/year

We Accept:
visa visa-debit mastercard maestro amex diners discover paypal