---
title: "How to change your URL in Moodle"
description: "When you are running a Moodle website, there may be times when you have to change your URL. For example, you may have sold the website, or maybe you purchased a shorter domain name, and want to..."
url: https://www.inmotionhosting.com/support/edu/moodle/change-url-moodle/
date: 2014-06-19
modified: 2021-08-16
author: "InMotion Hosting Contributor"
categories: ["Moodle"]
type: post
lang: en
---

# How to change your URL in Moodle

When you are running a **Moodle** website, there may be times when you have to change

your URL. For example, you may have sold the website, or maybe you purchased a shorter domain name, and want to replace the old one. In this tutorial we will show you how to change your URL in Moodle. We are going to use the **replace** script, that is included with Moodle. It essentially searches the database for the old URL, and replaces it with the new one. After changing your URL in Moodle, you may still need to [move the files](https://www.inmotionhosting.com/support/edu/cpanel/using-file-manager-in-cpanel/) to a new location, based on your setup.

**Note:** Any time you are modifying a database, we recommend [performing a backup](https://www.inmotionhosting.com/support/edu/cpanel/cpanel-backups/) first.

Get Started with Moodle on a [Dedicated Hosting](https://www.inmotionhosting.com/dedicated-servers) server today!

## Changing your Moodle URL

1. [Login to the Moodle Dashboard](https://www.inmotionhosting.com/support/edu/moodle/moodle-login-administrator/).
2. Add **/admin/tool/replace/index.php** to the end of the URL, and hit **Enter** on your keyboard. The address will look like this:**https://example.com/admin/tool/replace/index.php**(Be sure to replace example.com with your Moodle site. With older versions of Moodle add **/admin/replace.php** to the end of the URL.) You will then be on the *DB search and replace* page. It will look like this:[![Find and replace in Moodle](https://www.inmotionhosting.com/support/wp-content/uploads/2014/06/moodle_change-url_moodle-db-search-replace.png)](/support/wp-content/uploads/2014/06/moodle_change-url_moodle-db-search-replace.png)   You will also see a message stating “*This script is not supported, always make complete backup before proceeding! This operation can not be reverted! Several tables are not updated as part of the text replacement. This include configuration, log, events, and session tables.*“
3. In the *Search whole database for* field, enter your **existing URL**. in my test I entered: https://example.com
4. In the *Replace with this string* field, enter the **new URL**. In my test I entered: https://newdomain.example.com
5. Check the box for **Shorten result if necessary**. Confirm the change, by checking the box for **I understand the risks of this operation**, then click the **Yes, do it!** button.[![Changing URL in Moodle](https://www.inmotionhosting.com/support/wp-content/uploads/2014/06/moodle_change-url_search-replace-moodle-url.png)](/support/wp-content/uploads/2014/06/moodle_change-url_search-replace-moodle-url.png)  
6. It is finished when you see a message stating “*…finished*” at the bottom. Click the **Continue** button to return to the Moodle dashboard.[![URL changed in Moodle with replace.php script](https://www.inmotionhosting.com/support/wp-content/uploads/2014/06/moodle_change-url_url-change-finished.png)](/support/wp-content/uploads/2014/06/moodle_change-url_url-change-finished.png)  
7. Using FTP or File Manager, navigate to where Moodle is installed. Open the **config.php** file, and locate the line starting with:**$CFG->wwwroot **
8. Update the line to your new address, in my test I changed from this: $CFG->wwwroot = 'https://example.com'; To this: $CFG->wwwroot = 'https://newdomain.example.com'; Here is a screenshot of the updated line:[![Updating URL in config.php file in Moodle](https://www.inmotionhosting.com/support/wp-content/uploads/2014/06/moodle_change-url_updated-wwwroot-moodle.png)](/support/wp-content/uploads/2014/06/moodle_change-url_updated-wwwroot-moodle.png)  
9. **Save** your changes and you are done. Now you can move your site (if necessary) to the new folder location.

Congratulations, now you know how to change your URL in Moodle!
