Saturday 27 June 2015

Moodle : Incorrect access detected, this server may be accessed only through x address

Often when you install moodle within site directory and when you want to access directly you will see error.


Following amendment can be done to get rid off this error

Change the following file: /home/xxxxxx/public_html/moodle/lib/setuplib.php
Change -  setuplib.php
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
for
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 0);

Now when you access the link, Moodle redirects immediately to the www.<your registered domain> without the warning message.

Another solution is to make changes in .htaccess file

***************************************************************
suphp_configpath /home/myroot/public_html/php.ini
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domainname.com [nc]
rewriterule ^(.*)$ http://domainname.com/$1 [r=301,nc]
 i.e. replace the myhost.com  with your domain name
***************************************************************
The main advantage of this solution, you won't have to update the moodle code every time you update to a new version.

Hope this will solve the issue.

No comments:

Post a Comment