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 to a new location, based on your setup.

Note: Any time you are modifying a database, we recommend performing a backup first.

Changing your Moodle URL

  1. Login to the Moodle Dashboard.
  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:
    http://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

    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:

    http://example.com

  4. In the Replace with this string field, enter the new URL. In my test I entered:

    http://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
  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
  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 = 'http://example.com';

    To this:

    $CFG->wwwroot = 'http://newdomain.example.com';

    Here is a screenshot of the updated line:
    Updating URL in config.php file in Moodle
  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!

Continued Education in Course 300: Advanced Tutorials
You are viewing Section 4: How to change your URL in Moodle
Section 3: Fixing the "uploaded file may exceed the post_max_size directive in php.ini" error in Moodle
Section 5: How to install Moodle 2.3.2 manually
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

n/a Points
2014-08-07 9:43 am

What is the purpose of that "Shorten result if necessary" checkbox? What does it do?

Staff
10,345 Points
2014-08-07 10:17 am
Hello Andy,

Thank you for your question. When you run a query, depending n on your website, it can return a massive list of results.

The Shorten result if necessary option, makes the list less extensive. For example, if 2,000 lines of code were modified, it would shorten the results. It does not affect the functionality of your query. Unfortunately, I do not know the exact cut-off criteria.

If you have any further questions, feel free to post them below.
Thank you,

-John-Paul
n/a Points
2014-11-14 5:27 pm

Just wanted to note, in my case I also had to change this line in the config.php file:

$CFG->dataroot  = 'example.com';

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

3 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!