Loading
Cancel
Webmail Login
Control Panel Login
Moodle: How to redirect from www to non-www
.CO.UK ONLY £5.33
Find your perfect domain here

Moodle: How to redirect from www to non-www

Redirect moodle to non www or www

Moodle: How to redirect from www to non-www (vice-versa)

As with any website, you may be having trouble with your moodle site redirecting to the url that you require. With moodle, you may also be receiving an error message when you type in www / non-www before your url. This guide will help you to remove that error message and create a straightforward redirect.

If you type the url of your moodle site with www or without (whichever isn't set up as default), it may display this error message before redirecting:

Incorrect access detected, this server may be accessed only through "your web address", sorry. Please notify server administrator.

or

incorrect access detected this server may be accessed only through http //localhost address sorry. Please notify server administrator.

Error message

Obviously, this doesn't look too great if visitors have accidentally gone to the www / or non-www version of your site (depending on which you have as default).

To remedy this, you will need to do the following.

Create a .htaccess file

If you use an automatic redirect, you will never see this message. You can either create your own .htaccess file or click 'new file' in the file manager section of your Squirrel Hosting control panel.

To create your own, open up notepad and paste in the code below which is relevant to your site:

www to non-www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.YOURURL.com [NC]
RewriteRule ^(.*)$ http://YOURURL.com/$1 [L,R=301]

non-www to www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^YOURURL.com [NC]
RewriteRule ^(.*)$ http://www.YOURURL.com/$1 [L,R=301]

Make sure to replace the 'YOURURL' with your websites domain name.

You can now save this file as .htaccess (note the '.' before) and upload it via FTP. Whilst connected via FTP, you may also need to remove any extention e.g. '.txt' the file may have so it reads '.htaccess'.

To create the file via your Squirrel Hosting control panel, log in. Next, click on the 'file manager'

file manager

Navigate to your public folder (on Squirrel Hosting this is public_html). After this, click the 'new file' icon at the top of the page.

new file

A box will pop up asking for a filename. You can call this .htaccess.

htaccess

Next, a page will pop up where you can input the same text / code as detailed above (see pic below).

redirect

You can now save this file.

If you now try to access your site via www or non-www, it should go straight to your site without showing the error message.

We hope you found this guide helpful. We have another guide coming up regarding switching from www to non-www rather than redirecting. Keep an eye out for this guide.

If you have any comments, please give us your feedback below or click on our social buttons.



Leave a comment

Has this guide helped you? Have an idea for a guide or need help? Let us know below.

© Copyright 2014 | Squirrel Hosting Limited
Company Number 9031308