How To Do A 301 Redirect On A Single URL

Do you want to permanently redirect a single page or a few pages? Then a 301 redirect is what you would want. This article will discuss how to do a 301 redirect for a single page on your website

internet www
Image via pixabay.com

In this article, we will assume you are using Apache web server to host your website.

This article is about how to redirect one page or maybe a few pages. If you want to redirect an entire domain to another domain, read our article here on how to do that.

What is a 301 redirect?

A 301 redirect is a special type of redirect that is meant to be permanent. This is what is recommended by Google if you plan to redirect a page permanently.

It’s definitely bad for SEO to have broken links, duplicate content, or not redirecting a link properly. But properly configuring a 301 redirect shouldn’t hurt your SEO.

There are basically 2 ways to do a 301 Redirect. One is by using an .htaccess file (my preferred way). The second way is by editing Apache’s config files for your site.

Method 1: Redirect URL Via a .htaccess File

To make a 301 redirect for a page with a .htaccess file is actually very simple.

All you need to do is add a Redirect 301 line for each URL that you want to redirect somewhere inside your .htaccess file.

The syntax of a 301 redirect is like the following where oldlink is the URL you want to permanently redirect and newlink is the URL that you want to redirect to.

Redirect 301 /oldlink /newlink

Both the paths in the Redirect 301 line should be root relative. Root relative path means the path relative to the base of your site. So, for example, if you owned the site example.com, had the link example.com/sampleurl1.html and you wanted to redirect it to example.com/sampleurl2.html,
you would write something like:

Redirect 301 /sampleurl1.html /sampleurl2.html

And if you wanted to redirect to the base of your system, which is the root, you would just put a forward slash in the 301 redirect for where you want to redirect to.

So, for example, if you wanted to permanently redirect example.com/sampleurl1.html to example.com/
you would just do:

Redirect 301 /sampleurl1.html /

Summary For 301 redirects with .htaccess files

You just add a Redirect 301 line in the .htaccess as described in the steps above for every URL that you want to permanently redirect. And remember to save the .htacess file that you edited. It may take a few seconds for your server to update and permanently redirect one link to another depending on how fast your server is.

You can download a sample .htacess file that I made here.

Method 2: Modify The Apache Config File(s) For Your Old Domain

The steps here are very similar to those in method 1, but instead of editing the .htaccess file, you will be editing your Apache config file(s).

Let’s assume that you own example.com and have configured Apache. (You will of course need to change example.com to whatever your site is.)

To add a 301 redirect, you will need to edit the example.com.conf file.

Do the following steps

cd /etc/apache2/sites-available/

sudo vim example.com.conf

Then, somewhere in between the lines:

<VirtualHost>


</VirtualHost>

You will add a Redirect 301 line for each URL that you want to redirect inside the config file.

If you had the link example.com/sampleurl1.html and you wanted to redirect it to example.com/sampleurl2.html,
you would write something like:
Redirect 301 /sampleurl1.html /sampleurl2.html

If you wanted to permanently redirect example.com/sampleurl1.html to example.com/ you would just do:

Redirect 301 /sampleurl1.html /

It doesn’t really matter where you put the Redirect 301 lines as long as they are is somewhere in between the VirtualHost and /VirtualHost lines and and each redirect should be on its own line.

After you are done adding each Redirect inside the config file, save the file, and then restart Apache by typing the following:
sudo service apache2 restart

If your sites supports HTTPS, like if your site supports both https://example.com as well as http://example.com or your site redirects everything to HTTPS, you may also want to put the same redirects inside the SSL config file as well, just to be safe. So, if you owned example.com, you would edit example.com-le-ssl.conf and you would do the same steps as mentioned for the example.com.conf file.

You can download a sample apache config file with 301 redirects here. I put the 301 redirects at the bottom of the file.

See a real 301 redirect in action for a sample URL

I made a sample redirect URL just for this article. If you go to
linuxwebdevelopment.com/sample-redirected-page, it will redirect to this article located at https://linuxwebdevelopment.com/301-redirect-single-url/ . I did this by editing .htaccess file and adding the lines
Redirect 301 /sample-redirected-page /301-redirect-single-url
Though it would have worked the same way if I had edited it in its Apache config files.

Did you like this article? Do you have any questions about it? Let’s discuss it in the comments below.


🚀 Embark on an Epic Time-Travel Adventure with Watson! 🐕🦖🎨

Take a journey through time with Watson the Time-Travelling Dog: Dogs and Dinosaurs Adventure Coloring Book 1.

Join Watson and his dog brother Sherlock as they meet dinosaurs, make new friends, and embark on an unforgettable adventure! Perfect for kids, dog lovers, and coloring book enthusiasts alike.

Why you'll love it:

  • Engaging, fun-filled story
  • Beautiful illustrations to color
  • Ideal for family fun or a thoughtful gift

Ready for an adventure that sparks creativity and fun? 📖 Grab your copy today and let the time-traveling excitement begin!

Get your book now 👇

Get your book here!

13 thoughts on “How To Do A 301 Redirect On A Single URL”

    1. Thanks. You don’t really have to know much about tech to do a 301 redirect. There are even some WordPress plugins that can do them for you if you are afraid of typing in a few lines of code. But, definitely 301 redirects have been very useful for me.

  1. Never knew what a 301 redirect was. Now pretty clear about what the redirect does. This will help me when i am changing my pages name or considering a rebrand. Cheers

  2. wow – I need you in my life – so glad I found your blog – i’m sooooooo technologically inept!

    1. Thank you very much. And yes it is very useful. In addition to the steps I described, you could also use WordPress plugins to do a 301 redirect if you are not comfortable doing it yourself.

  3. Definitely imagine that that you stated. Your favorite justification appeared to be on the
    internet the easiest factor to be aware of. I say to you, I definitely get
    annoyed whilst other people think about concerns that they just do not
    recognise about. You managed to hit the nail upon the
    top as neatly as defined out the whole thing
    with no need side-effects , folks can take a
    signal. Will likely be back to get more. Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *