Incorrect redirect from root

Incorrect redirect from root

by Rodrigo Villarreal -
Number of replies: 5

I searched for this problem but I was unable to find an answer.

Here is the background:

On the moodle config file, I used to have the following value:

$CFG->wwwroot   = 'https://mysite.edu/moodle';

I then needed to charge for course subscription and hence decided to make the entire site secure, I then replaced the above value on my config file as follows:

$CFG->wwwroot   = 'https://mysite.edu/moodle';

In short, I replaced http for https. I initially, it all seemed to be working smoothly until I realized that I was unable to install plugins. Every time I wanted to do so, it shows me the pesky "Incorrect access detected, this server may be accessed only through "[address]" address, sorry." It then tries to redirect me in a loop, never being able to leave that page.

Strangely enough, this also occurs when I click on the logo link, even though the actual link appears to be correct when I mouse over the logo. It points me to the above error message and never redirects me, or I should say, it does try to redirect me every 3 seconds, but it appears to be on a loop.

Somehow, I presume that there are links that attempts to direct me to the old URL. I thus made sure to clear all caches from the site and the theme, to no avail. I even looked for all references to the OLD URL addresses on phpMyAdmin, and I replaced them with the NEW URL, and that still did not work. I also searched for any reference to the OLD URL on the installation files, and there are absolutely none. So this is really baffling me.

As a last note, I should mention that I already tried to modify the file lib/setuplib.php by replacing the line:

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

for

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

and did not work either because I was receiving an error message form Firefox to the effect that the page could never load.

Can anyone shed any light to this mystery?

Average of ratings: -
In reply to Rodrigo Villarreal

Re: Incorrect redirect from root

by Luis de Vasconcelos -

Unfortunately, the wwwroot address that you use when you install Moodle gets stored inside the Moodle database in several places. So, to fix your site you might need to run the Replace script (http://yoursite.com/admin/tool/replace/) to change the "http" in your wwwroot address to "https".

Use the script to search for "http://mysite.edu/moodle" and replace it with "https://mysite.edu/moodle".

And please vote for MDL-35099!

In reply to Luis de Vasconcelos

Re: Incorrect redirect from root

by Rodrigo Villarreal -

Thanks Luis,

I did use the tool you suggested, to no avail. (I had previously made a manual replacement using phpMyAdmin, as I mentioned above). I was unaware of the replacement tool, and it sure is nice to have it, as I managed to replace some 30 instances of the incorrect URL.

However, as I mentioned, the problem persists. How does the old URL still hanging around is beyond me.

You can see it clearly here on a production site:

https://pharmacyce.uic.edu/moodle

If you click on the logo link, somehow one is redirected to http://pharmacyce.cc.uic.edu/moodle. How is that possible?

Can anyone provide any other suggestions?

Thanks in advance.

In reply to Rodrigo Villarreal

Re: Incorrect redirect from root

by Ken Task -
Picture of Particularly helpful Moodlers

SSL for site might not be configured correctly.  Consult server docs to check that it is.

Might also have something to do with DNS entries for the site ...

dig pharmacyce.uic.edu shows the same IP address as dig pharmacyce.cc.uic.edu but

dig -x the_IP_ADDRESS (a reverse lookup) shows only one PTR record for pharmacyce.cc.uic.edu.

If you no longer need the pharmacyce.cc.uic.edu for other apps on that server, drop that entry in DNS.

This assumes that the correct URL for the site is in config.php and that the search and replace tool has found and replaced all references of oldsite with newsite.  Also check apache config (assuming you are using apache) to see if #ServerName is set correctly (could comment that out really) and UseCanonicalName Off.  If you make changes to apache conf, restart of apache is required.

Might also set ServerSignature Off ... an xxx URL discloses what you are running apache and OS wise.

And check /etc/hosts file to see how server is configured to know about it's own hostname.

'spirit of sharing', Ken

In reply to Ken Task

Re: Incorrect redirect from root

by Rodrigo Villarreal -

Thank you so much Ken. I'm not a network administrator and I do not have full access of the server as it is hosted at the University. It may take a few days for a request to be implemented to drop the DNS entry,  to verify if #ServerName is correctly set and make sure UseCanonicalName is also set to Off. Yes, the URL is configured correctly into config.php and I have made sure all instances of pharmacyce.cc.uic.edu have been replaced to pharmacyce.uic.edu in the database.

Once this is done (assuming it can be done), I will report back. Still, this is really weird.

Thanks again for your suggestion Ken.