PDF download Download Article
Easily redirect a page, post, website, or domain with this easy guide
PDF download Download Article

If your website gets a lot of traffic and ranks high in search engine results, things can get tricky if you need to change the domain or URL. Redirecting a URL during the transition ensures that all visitors to your original website are automatically sent to its new location. You can also use redirects to direct visitors to another page on the same website. This guide will teach you how to redirect a URL to another website or domain, both on the server side (301 and 302 redirects) and the client side (meta refresh redirects, PHP, and JavaScript redirects).

Redirecting a URL to Another Location

  • To permanently redirect a URL to another location, use a 301 redirect. You can create one in your website's .htaccess file, in cPanel, or using a WordPress plugin.
  • To redirect a URL temporarily, use a 302 redirect, a meta refresh redirect, PHP redirect, or JavaScript redirect.
  • If you don't have access to your web server configuration, you can create a meta refresh redirect, PHP redirect, or JavaScript redirect by editing your website's code.
Section 1 of 7:

301 or 302 Redirect (.htaccess)

PDF download Download Article
  1. If the URL is moving permanently, you can use a 301 redirect to send traffic to a different URL. If you manage your website by editing files manually, you can create your redirect in a file called .htaccess . The file is usually in your website's root directory (typically called public_html , htdocs , or www ). Download the file and open it in a text editor like Notepad for Windows or TextEdit for Mac, or edit it directly on the server if you have access to do so.
    • If there is no .htaccess file, your web server may not be an Apache server. Contact your web host for instructions on creating a redirect.
    • If the redirect is temporary, you can create a 302 redirect. Just replace 301 in our examples with 302 to indicate that the URL redirection is not permanent.
    • If your website uses WordPress, you can use this method if you can edit your web server configuration files by hand.
  2. To create a redirect, you'll need to enable the rewrite engine in the Apache mod_rewrite engine. If you don’t see the following code, add it to the bottom of the file:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    </IfModule>
    Advertisement
  3. Now that the rewrite engine is enabled, you can add your redirects just below the line "RewriteEngine On." If you only want to redirect a particular page or directory on your website to another location, add a redirect like this:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    Redirect 301 /oldpage https://example.com/newpage
    </IfModule>
    • "Redirect 301" indicates that we're doing a 301 (permanent) redirect. After that comes the path to the directory on your webserver (or the file) that you're redirecting elsewhere. Last is the URL you're redirecting to .
    • In the above example, all visitors to the /oldpage directory on the website will be routed to the /newpage directory of example.com.
    • You can redirect files (e.g., index.html) and directories (e.g., /about/) to local or remote directories. For example, to redirect https://mywebsite.com/oldpage/index.html to https://example.com/newpage/), you'd use Redirect 301 /oldpage/index.html https://example.com/newpage/) .
    • You can also redirect a URL to another file on the same web server—just leave out the domain name on the second part of the redirect. For example, if you changed the name of index.html to home.html, you can redirect Redirect 301 /index.html /home.html .
  4. If you are switching domain names and want all traffic to your existing website to go to the new website, you can do so by adding the following line to the bottom of your .htaccess file:
    <IfModule mod_rewrite.c>
    Redirect 301 / https://example.com/
    </IfModule>
    • In this example, all hits to this website's domain name will automatically be redirected to the URL https://example.com .
  5. Once you've added your redirect, you'll need to place it back into the root directory of your website. If you downloaded the file, do not add a file extension (e.g., txt) when saving the new file.
    • Test the redirect in a private (incognito) window. Open a new private browsing window and type the old URL into your browser. If you've done everything correctly, it will redirect you to the new site.
  6. Advertisement
Section 2 of 7:

301 or 302 Redirect (cPanel)

PDF download Download Article
  1. If you use cPanel to manage your website , you can redirect a URL to another—either a 301 (permanent) or 302 (temporary) redirect—without editing any text files manually.
  2. Configuration options for the domains hosted on your account will appear.
  3. Now you'll see the option to redirect an individual page, a domain, or all hosted domains to another URL.
  4. If you plan to redirect the URL to the new address permanently, select Permanent (301) . If the redirect is only temporary, select Temporary (302) . [1]
    • If a visitor has the page bookmarked, a 301 redirect will automatically update the bookmark to reflect the URL change.
  5. To redirect all hits to all of your hosted domains to another URL, select All Public Domains from the "https://?(www.)?" menu. Otherwise, select the domain name you want to redirect. If you just want to redirect one page on that domain to another URL, enter the path to that page into the "/" field.
    • For example, if you want to redirect https://example.com/about/home.html to another URL, enter example.com into the first field, and about/home.html into the second.
  6. Enter the URL you want to redirect to. In the "Redirects to" field, type the full URL (including https:// or another protocol) into the field.
  7. If you want to redirect traffic to the URL regardless of whether the user types www. before your domain name (e.g., you want to redirect both https://www.example.com and https://example.com), select Redirect with or without www. Otherwise, you can select whether to redirect only when www. is included, or only when it is not.
  8. If you are in the process of moving your website to a new location and want to redirect hits to all files and directories on the current site to the same structure on the new site, check the box next to "Wild Card Redirect."
    • For example, all hits to files/directories like https://www.example.com/picture.jpg and https://www.example.com/users/ will redirect to https://www.newdomain.com/picture.jpg and https://www.newdomain.com/users/.
  9. Now that you've added a redirect, you can test it in a new browser tab or window.
    • It's not possible to edit an existing redirect. If you need to make a change, you must delete the redirect and then recreate it. [2]
  10. Advertisement
Section 3 of 7:

301 or 302 Redirect (WordPress)

PDF download Download Article
  1. If you use WordPress and can't (or don't want to) edit the .htaccess file manually , you can create 301 (permanent) or 302 (temporary) redirects easily with this plugin. [3] You can get the plugin from https://wordpress.org/plugins/redirection/ .
    • To install the plugin, download the ZIP file from the website, unzip it , and upload the redirection directory to your /wp-content/plugins directory. [4]
    • Once installed, enable the plugin on the plugin management page.
  2. You'll see the Tools menu on the left panel in your WordPress installation. This is where you can manage all of your URL redirects. [5]
  3. You'll see this in the top menu bar.
  4. The source URL is relative to your website, which means instead of entering https://www.example.com/home.html to redirect home.html , just enter /home.html .
  5. Enter the URL you want to redirect to. If you're redirecting to another domain, enter the full URL (e.g., https://www.newdomain.com). If you're redirecting one page to another on the same domain, you can use a relative URL like .
  6. Here's where you can fine-tune your redirect.
  7. Select Redirect to URL from the "When matched" menu, then choose the redirect type ( 301 – Moved Permanently or 302 – Moved Temporarily ) from the "with HTTP code" menu. [6]
  8. Once your redirect is live, the source page will automatically route traffic to the destination URL.
    • You can edit any of your saved redirects by clicking Edit below its entry.
  9. Advertisement
Section 4 of 7:

Meta Refresh Redirect

PDF download Download Article
  1. A meta redirect allows you to redirect a single webpage to another URL using a simple HTML tag. It's usually better to go with a 301 redirect for a permanent URL redirect. But if you don't have access to your web server configuration, an instant meta refresh redirect is the next best option, and is also interpreted by Google as a "permanent" redirect. [7]
    • Some people believe that meta refresh redirects may be seen as spammy and thus negatively impact your SEO performance . Google doesn't say this for sure, but it's something to remember.
  2. In this example, we'll create a redirect that sends the user to https://www.newsite.com/newurl.html as soon as the page loads. The "0" indicates 0 seconds, or an instant redirect.
     <!doctype html> 
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     meta 
     https-equiv 
     = 
     "refresh" 
     content 
     = 
     "0; URL=https://www.newsite.com/newurl.html" 
     > 
     </ 
     head 
     > 
    
  3. Once the file is reuploaded, you can test the redirect in any web browser. As soon as the page loads, you'll be taken to the URL specified in the redirect.
  4. Advertisement
Section 5 of 7:

PHP Redirect

PDF download Download Article
  1. If you want to redirect a PHP page to another location, you can create a permanent PHP redirect using the header() function. PHP redirects can send users to any URL or local file, even if the destination isn't a PHP-based page.
  2. In this example, we'll redirect hits from the current page to https://www.example.com :
     <?php 
     header 
     ( 
     "Location: https://www.example.com/" 
     ); 
     ?> 
      
    
    • If you want to redirect the user to a different page on the server, replace the URL with a local path (ex. <?php header("Location: NewSite/index.php"); ?> .
    • [8]
  3. Now, when visitors open the page in their browsers, they'll be redirected to the specified URL.
  4. Advertisement
Section 6 of 7:

JavaScript Redirect

PDF download Download Article
  1. While less common than 301 and meta refresh redirects, JavaScript redirects can come in handy if you cannot use either of the options above. However, because JavaScript redirects can prevent search engine crawling bots from properly indexing pages, you should only use this type of redirect if you're not worried about SEO or need a temporary option. [9]
  2. In this example, we'll redirect all hits to the URL specified in this code.
     <!doctype html> 
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     script 
     > 
     window 
     . 
     location 
     . 
     href 
     = 
     "https://www.example.com/newlocation" 
     ; 
     </ 
     script 
     > 
     </ 
     head 
     > 
    
  3. Once the file is accessible online, anyone visiting that page will be redirected to the specified URL.
  4. Advertisement
Section 7 of 7:

What type of redirect should I use?

PDF download Download Article
  1. If you're changing your URL structure, switching to a new domain name, updating your URL structure, or making any other permanent changes, always use a 301 redirect to ensure the best experience for your visitors.
    • If a visitor has the page bookmarked, a 301 redirect will also automatically update their bookmark to reflect the new address. [10]
  2. If you want to temporarily send visitors to another URL and have access to your web server configuration, a 302 redirect is the best option. However, if you can't access your web server configuration, you can opt for a meta refresh redirect, or use a PHP redirect if your website uses PHP . A JavaScript redirect should be your last option, as it can negatively impact the user's experience and your website's search engine performance .
  3. Advertisement

Expert Q&A

Search
Add New Question
  • Question
    Can you redirect a URL to a specific page?
    Stan Kats
    Professional Technologist
    Stan Kats is a Professional Technologist and the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan holds a BA in International Relations from The University of Southern California. He began his career working in the Fortune 500 IT world. Stan founded his companies to offer an enterprise-level of expertise for small businesses and individuals.
    Professional Technologist
    Expert Answer
    Yes, you can—just use your website's settings to redirect your site to a different page. If your host doesn't have that type of setting, set up a very simple site that automatically redirects the visitor to another page.
  • Question
    Can I redirect a website that I don't own using only my computer?
    Community Answer
    It depends on what you mean by redirect. If you mean to redirect incoming traffic from the website to wherever you want it to go, then the short answer is no. It's possible, but also illegal depending on where you are, and what the laws are. If you want to direct a link to a destination of your choice, use something like TinyURL or RarME.
  • Question
    Can it be sent straight to a message with no URL?
    Community Answer
    You could write a javascript routine that just spits out whatever text you want it to say, but you'd still have to include that in your index.html page. At that point, you might as well just place your message in your index.html or home.html page. Then again, I'm no javascript expert. Check some of the javascript code libraries, you might find what you want; then you just cut and paste.
See more answers
Ask a Question
      Advertisement

      Video

      Tips

      • While some websites use an error page explaining a change of URL and include a clickable redirect link, this is less efficient than an automatic redirect and can end up costing your new site a significant percentage of visitors.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Article Summary X

      1. Open the .htaccess file on the web server.
      2. Type redirect 301 /old/oldURL.com http://www.newURL.com .
      3. Replace the "newURL" section of the code with the website you want to redirect to.
      4. Save the file and re-upload if necessary.

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 1,570,859 times.

      Is this article up to date?

      Advertisement