General developer forum

 
 
Picture of Daniel Garcia Sanchez
how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Hello friends smile

I would like know if it is possible to remove this message from appearing on screen when accessing: mydomain.com/moodle instead of www.mydomain.com/moodle

"Incorrect access detected, this server may be accessed only-through x address, sorry."

I would like, if possible, to redirect directly to the cover of my moodle, without waiting for this message. I have asked for this in the spanish forum of moodle, and they said to me that I one way is creating a record "CNAME" but I don't know how create it, because when I try to create one record of this type from my panel of plesk, I have to give values to two parameters: domain's name and canonical name...sorry for my ignorance

Best regards and thanks in advance, Daniel

 
Average of ratings: -
Picture of Andrea Bicciolo
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

If you are working with Plesk, there are good chances you already have a CNAME record for www.yourdomain.tld with the following syntax on the DNS zone:

www.yourdomain.tld CNAME yourdomain.tld

That could be confirmed by the fact your web server answers to requests adressed to both http://yourdomain.tld and http://www.yourdomain.tld

In any case, in the CNAME example above, "yourdomain.tld" is the canonical name (and you should find it in the Plesk DNS zone as recordy type A with an IP address), while "www.yourdomain.tld" is the domain name.

 
Average of ratings: -
Picture of Howard Miller
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
The underlying problem is that you can't do that.

Moodle will only work with one value of 'wwwroot' in config.php. You have to pick one and stick with it. You could arrange a web server re-write or redirect to ensure that any 'wrong' URLs get redirected to the front page of your Moodle with the correct URL, but you can't run with an alias.
 
Average of ratings: -
Picture of Daniel Garcia Sanchez
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

is possible change the waiting time of this message to 1000ms instead of 3000ms?

thanks, Daniel

 
Average of ratings: -
Picture of Howard Miller
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
In lib/setuplib.php look for this line

 
    redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
 


Change the 3 to 1.
 
Average of ratings:Useful (2)
Picture of Daniel Garcia Sanchez
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Hey Howard! Thanks very much for your reply wink

 
Average of ratings: -
Picture of Gabriel R.
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

This approach only works if you are trying to access the moodle site root.  For example, on our moodle site, when a non-authenticated user accesses the site, they are presented with custom images that link to login and signup.

So, if our setup in config.php is "$CFG->wwwroot = 'http://www.mysite.com';", we would get this error message when trying to access mysite.com/, and with the above solution, it forwards nicely to www.mysite.com, BUT if we have linked our signup image to "mysite.com/login/signup.php", it forwards to www.mysite.com/ - but does not include the rest of the path.

 
Average of ratings: -
Picture of Hubert Chathi
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

If you control the link, why not just make it link to www.mysite.com/login/signup.php instead?

 
Average of ratings: -
Picture of Clarence Prudhoe
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Hi,

If you add the following instructions to your .htaccess file, it will force a redirect to http://www.mysite.com.   If you use this solution, you won't have to update the moodle code every time you update to a new version.

suphp_configpath /home/myroot/public_html/php.ini
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^fbcph.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]

This worked for me.
Clarence

 
Average of ratings: -
Sketch...
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group Particularly helpful Moodlers

MDL-35099 would also be useful in this situation...

 
Average of ratings: -
On the jetty
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Thnaks to Clarence and the assistance of a collegue in our office we got the following code to work with the .htaccess file to redirect from http://www.myhost.com straight to http://myhost.com

 

suphp_configpath /home/myroot/public_html/php.ini
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.myhost.com [nc]
rewriterule ^(.*)$ http://myhost.com/$1 [r=301,nc]

 i.e. replace the myhost.com  with your domain name

Thanks

 

 
Average of ratings: -
hungry_kitten
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

It worked perfect for me! I changed it to 0 though. Thanks Howard!

 
Average of ratings: -
Picture of Joseph Rézeau
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Daniel, Andrea and Howard.

I've just been confronted with this problem on my local moodle installation. In order for my desktop localhost moodle sites to be accessed from my laptop and tablet, I need to replace

$CFG->wwwroot   = ' http: //localhost/moodle21fork/moodle';

with

$CFG->wwwroot   = ' http: //192.168.1.10/moodle21fork/moodle';

where 192.168.1.10 is the IP of my desktop machine.

Now, when I log in to my moodle 21 test site, I get the obnoxious message:

Incorrect access detected, this server may be accessed only through "http: // 192.168.1.10/moodle21fork/moodle" address, sorry.
Please notify server administrator.
(Continue)

What is the point of that message, since it does not prevent access to my moodle site, after a few seconds' delay? By the way, the message is illogical, as it says the server can only be accessed through an address which is precisely the URL that has been typed in the browser. Weird!

Joseph

 
Average of ratings:Useful (1)
Picture of Andrea Bicciolo
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Jospeh,

interesting point, yes the message could be better but according to your test it appears some logic is not working as expected.  You may want to  open a tracker issue for this?

 

 
Average of ratings: -
Picture of Hubert Chathi
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

AFAIK, the point is to prevent people from trying to publish multiple URLs to access the same Moodle site.  Moodle does not handle being accessed from multiple URLs well.  In previous versions, Moodle didn't check, and you would be able to use multiple URLs, but strange things could start happening.

 
Average of ratings:Useful (1)
C'est moi :-)
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
Group Documentation writersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi,

Do you have some pointers about that?

Since 2/3 months, and after a domain change, i've put these lines in my config.php file, to allow my Moodle to be accessible from several (2) adresses (defined in apache virtualhosts) :

$CFG->wwwroot = 'http://default_old_domain/moodle';
if (isset($_SERVER['HTTP_HOST'])) { $CFG->wwwroot = 'http://'.$_SERVER['HTTP_HOST']; }

In fact, it automatically adapt's from the used URL to access the Moodle site.

Séverin

 
Average of ratings: -
Picture of Daniel Garcia Sanchez
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Finally I solved it by changing, in lib/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 I access in the way: mydomain.com , moodle redirects inmediately to the www.mydomain.com

Thanks to Howard, Daniel

 
Average of ratings:Useful (8)
Picture of Rachel Fransen
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Thanks for posting this solution - works for me as well! smile

 
Average of ratings: -
Picture of José Ángel Polo
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Thanks

 
Average of ratings: -
Picture of tim st.clair
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

I need to be able to DEBUG my skin using a variety of browsers. I run a mac, and moodle runs on MAMP just fine on the local machine. None of the current thread solves my problem at all.

In order to test other browsers, such as IE7 on Windows, I run virtualbox. This normally lets me access my own other non-moodle sites by using the 10.0.2.2 loopback address, which is part of virtualbox.

So on MAMP on MAC, I have to use the address http://locahost/moodle22/

On IE7/XP on VIRUTALBOX, i have to use the address http://10.0.2.2/moodle22/

But I get the warning Incorrect access detected, this server may be accessed only-through x address, sorry.

Perhaps there's some way I can set up a DNS server on the mac? So that I can make a reference to, say, moodle22.mybox.local as a domain name. Please note that this is my Air, it is where I develop, it is not a server. I do not want OSX Server.

I do not know how to do this on a mac, and I do not have a windows server that I could do it on. This is not live on the internet.

 
Average of ratings: -
Picture of Edmund Edgar
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

Hi Tim.

If you want to make a hostname for testing that only works from one computer (or virtual computer), you can do it by editing the hosts file. On a Mac or Linux, this lives at /etc/hosts. On Windows, it lives somewhere like C:\Windows\System32\drivers\etc\hosts.

On the mac, add to your /etc/hosts file:

127.0.0.1    moodle22.mybox.local

On the Virtual Box, add to C:\Windows\System32\drivers\etc\hosts:

10.0.2.2    moodle22.mybox.local

 
Average of ratings: -
Picture of Kevin Phelps
Re: how to remove the message "Incorrect access detected, this server may be accessed only through x address, sorry."
 

You can also used "Bridged Networking" in Virtual Box so each system is given an actual IP address. That way you can run the server in either the host or virtual computer and set $CFG->wwwroot to the "server" IP address. You can then use the "server" IP address in the browser of both computers along with others on the network.

Edit: This solution may not work if you are not connected to the Internet, but should work if you have a non-Internet LAN.

 
Average of ratings:Useful (1)