Login not worfking, duplicate domain name in URL

Login not worfking, duplicate domain name in URL

door Andrew Kwabula -
Aantal antwoorden: 13

This problem started after I renewed the domain's SSL. When I installed moodle on the subdomain, the website was already on HTTPS. This subdomain remained on HTTP. Upon renewing the main domain's SSL, this subdomain started redirecting to HTTPS but would wasd not displaying properly. The SSL for the main domain does not include this subdomain. So I purchased an SSL for this subdomain. Now the site works well, every URL works except the login which shows a duplicate domain name and no login form (Linux server, Moodle 4.01, Academi theme)

The moodle site is set on a subdomain. When I hover over the login link, I can see at the bottom left corner that it points to https://elearning.kaumbasecondary.org/login/index.php. But when I actually click on it the URL in the address bar is: https://elearning.kaumbasecondary.org/elearning.kaumbasecondary.org/login/ and the login form is not displayed, the duplicate URL loads the home screen. 

Somehow, https://elearning.kaumbasecondary.org redirects to https://elearning.kaumbasecondary.org/elearning.kaumbasecondary.org/login/ . I have to delete the duplicate domain from the URL to get the site to display the login page. 

I turned on debugging to display all errors but no error is shown for this. I tested the debugging by messing up with the webroot and sure enough, the site spat errors right in the browser. So whatever is causing this is not showing in the PHP error log. 

What could be happening?


Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

Moodle caches everything ... so first manually delete from moodledata the contents of /cache/ /localcache/ /muc/.    Also clear your browser cache and cookies for the site.

After adding/changing cert setup, did you restart the apache service?

Does your config.php file have https:// or is it still http://?

A curl -I test of the TLD - elearning.

curl -I https://elearning.kaumbasecondary.org/

renders this:

curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.se/docs/sslcerts.html


curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Many use a redirect for all port 80 traffic to be redirected to port 443 (ssl).  Check that config is correct.

https://www.google.com/search?client=firefox-b-1-d&q=redirect+port+80+to+443

Your Certificate entity usually has instructions for how to setup the certs depending upon your Linux OS.   Example: a CentOS 7 server running apache has an ssl.conf file in /etc/httpd/conf.d/  

IF you have the same OS and there is an ssl.conf file, check these configuration items:

#   Server Certificate:

#   Server Private Key:

#   Server Certificate Chain:

If using another OS, check it's docs for setting up an SSL cert on that OS.

'SoS', Ken


Gemiddelde van de beoordelingen:  -
Als antwoord op Ken Task

Re: Login not worfking, duplicate domain name in URL

door Andrew Kwabula -
Ken, I am super grateful for your help. Unfortunately, I am still struggling with the same problem.
As you suggested, I:
went ahead and sorted out the certificate problem. I had some self-signed certs so I installed the wrong one. After reading your response, I went and installed a proper certificate so no errors related to the cert.
config.php file already had https because the site could no longer work with http.

My moodle installation does not have the path /cache/ /localcache/ /muc/. So I looked for the muc folder, starting with a period: .htj9zt7bekj93n.data inside are the following folders: cache, diag, filedir,localcache, muc, sessions, temp, trashdir and an .htaccess file

Inside the muc folder was just a config.php file. I deleted it and the system regenerated it.

What should I delete from which folders are listed above? Or from elsewhere?

I also purged all caches from Site Administration > Development > Purge all Caches

I am still getting, a duplicate domain in the URL ( https://elearning.kaumbasecondary.org/elearning.kaumbasecondary.org/login/ ) so end up at the home page when I click to log in.

Hovering on the login link shows it pointing to
http://elearning.kaumbasecondary.org/login/index.php

how clicking on it loads
https://elearning.kaumbasecondary.org/elearning.kaumbasecondary.org/login/ (I notice the index.php at the end is missing)
is surprising. Before it used to load the same exact URL I see on hovering.

Kindly let me know what else I can do to solve this issue.

Update:

Interesting behaviour: if I paste, elearning.kaumbasecondary.org/login/index.php in the address bar (the URL the log in link is pointing to), it changes to the problematic URL:  elearning.kaumbasecondary.org/elearning.kaumbasecondary.org/login/  (index.php removed)
but 
if I paste elearning.kaumbasecondary.org/login/ (leaving out the index.php), the URL holds and the Login page loads, with no duplicate domain. 

It looks like the index,php is what is making the system throw tantrums? 

Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

Check your config.php file in moodle code directory (/elearning/).

There is a line for wwwroot which is really the URL to the site:

$CFG->wwwroot   = 'URLto/elearning';

with no trailing slash at the end.   If you edit that file make sure you are using a true text editor.

Sounds like site is being redirected by apache.   That's normally done via .htaccess files.   Those files are hierarchal ... if have one at document root it rules the roost.

The /muc/ /cache/ are in your moodledata directory .. path seen in config.php

index.php should not be edited by you ... that came with the package.as

If your site was http:// before and now it is https:// there is an admin tool to do search and replace for DB - backup database first.

https://docs.moodle.org/30/en/HTTPS_Search_and_replace

'SoS', Ken


Gemiddelde van de beoordelingen:  -
Als antwoord op Ken Task

Re: Login not worfking, duplicate domain name in URL

door Andrew Kwabula -
Thank you very much, Ken.
The wwwroot is set without a trailing slash and with https.
.htaccess is blank, the one in the root directory.

I notice that adding index.php to the duplicate URL has the effect of adding one more domain name to the URL and the resultant URL excludes index.php with a training slash after login

I am new to moodle so I have no idea what moodle puts in a .htaccess file
Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

If .htaccess is 'blank' ...has nothing in it ... no need for it then ... rename it to htaccess.txt and apache won't try to use a blank .htaccess file.

Moodle might put an .htaccess file in moodledata to make sure no one can surf to that directory if it were in document.   But I've never see moodle use .htaccess in it's code root.

So let's review ... do we want:

https://elearning.FQDN/elearning/ (moodle code is in /elearning/)

or

https://elearning.FQDN/

Not only apache config/moodle config is in play, but DNS as well.

dig www.elearning.kaumbasecondary.org

dig elearning.kaumbasecondary.org

'SoS', Ken

Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

6:30 PM my time ...

Just did a curl test ...

curl -I https://elearning.kaumbasecondary.org/

shows that your moodle code isn't in /elearning/ but document root as defined by apache config.

AND

the way your web server is setup, the URL to your site is:
www.elearning.kaumbasecondary.org

Curl test showed:

curl -I http://elearning.kaumbasecondary.org/
HTTP/1.1 301 Moved Permanently
Date: Fri, 27 May 2022 23:27:37 GMT
Server: Apache
Location: https://elearning.kaumbasecondary.org/
Content-Type: text/html; charset=iso-8859-1

That's of the time I did that! glimlach

'SoS', Ken

Gemiddelde van de beoordelingen:  -
Als antwoord op Ken Task

Re: Login not worfking, duplicate domain name in URL

door Andrew Kwabula -
Thanks very much for your time and skills.
So I tried https://www.elearning.kaumbasecondary.org , this says 'this site cannot be reached' despite adding wwwroot in config.php. I remove the www and the site loads just with the problem where the login page does not work.

The SSL was issued to cover the www variant of the URL.

curl -I http://elearning.kaumbasecondary.org/ probably because of the installed SSL. So that could be why it shows movement.

At this point, I feel like I have hit a brick wall.

I really appreciate your help, the problem is this is my first Moodle site so I appreciate your immense patience.
Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

We've a combo of issues ... Apache web server config, moodle config, and DNS/Cert included. droevig

A DNS dig - looking for the IP address of fully qualified domain name given:
dig www.elearning.kaumbasecondary.org

Returns NO A record.   Meaning no IP address is associated with it.

Your top level domain ... kaumbasecondary.org.

;; AUTHORITY SECTION:
kaumbasecondary.org.    600    IN    SOA    ns49.domaincontrol.com. dns.jomax.net. 2022051900 28800 7200 604800 600

show DNS servers are ns49.domaincontrol.com and dns.jomax.net.

dig @ns49.domaincontrol.com www.elearning.kaumbasecondary.org
no answer ... no A record for www.elearning.kaumbasecondary.org

The other DNS server, dns.jomax.net doesn't appear to exist!!!

dig dns.jomax.net

Gets no answer.

www.kaumbasecondary.org. Does exist and a curl test shows:

HTTP/2 200
x-powered-by: PHP/7.4.29
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
set-cookie: ci_session=974d77d2abca47d72cd98f3cb82983f2bba1ee11; expires=Sat, 28-May-2022 05:52:56 GMT; Max-Age=14400; path=/; HttpOnly
vary: Accept-Encoding
content-type: text/html; charset=UTF-8
date: Sat, 28 May 2022 01:52:55 GMT
server: Apache

A dig for www.kaumbasecondary.org shows:
;; ANSWER SECTION:
www.kaumbasecondary.org. 10688    IN    CNAME    kaumbasecondary.org.
kaumbasecondary.org.    10688    IN    A    92.205.1.71

So that server exist ...
now let's talk moodle ... where is your moodle server?
On IP address above?
elearning.kaumbasecondary.org
dig eleearning.kaumbasecondary.org
;; ANSWER SECTION:
elearning.kaumbasecondary.org. 4513 IN    A    92.205.1.71

**** SAME IP ADDRESS AS YOUR www site.

So on that IP addressed server, you must be running virtual apaches.
Each host (www and elearning) have an apache config file and from the looks of it,need a separate  certificate ... don't think one can use a 'global' (*.kaumbasecondary.org) certificate in apache.  And you can use https on elearning because the cert was for host www!

From what CA did you get your cert?

Assume your server is linux ... what flavor?  Ubuntu, Debian, CentOS, RedHat, other?

Am going to send to you here in this forum a private message with a question.   Please respond there!

'SoS', Ken


Gemiddelde van de beoordelingen:  -
Als antwoord op Ken Task

Re: Login not worfking, duplicate domain name in URL

door Andrew Kwabula -
Ken Task made me think about the .htaccess.
The .htaccess in the root directory of the elearning subdomain was empty. I looked up, went into the domain and looked at the .htaccess. I have the following:

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Force a 301 redirect for HTTPS to work
#———————————————
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

and I also have

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?kaumbasecondary.org$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

I have never had any problems with sub-domains in the past. Even here, only the login page is affected. That is why I never suspected that the domain's .htaccess was causing the subdomain problems, the moodle site.

So I deleted the .htaccess, cleared cache in moodle and cleared the browser history and the moodle site worked flawlessly.

The problem is that the main site stopped working, It needs the .htaccess. So I added the following to the .htaccess just after RewriteEngine On

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?[^.]+\.[^.]+$ [NC]

So now the login page is working and the main site is working. The rule excludes the subdomain from being affected by the domain's .htaccess.

'SOS' Ken THANK you very much, you took me on a journey that led to the solution, YOU solved my problem.
Gemiddelde van de beoordelingen: Useful (1)
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Ken Task -
Foto van Particularly helpful Moodlers

Congrats and welcome!

Yes, Moodle is a 'never ending journey!' ;)

'SoS', Ken


Gemiddelde van de beoordelingen: Useful (1)
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Philips habah -
Best wishes and gladly accept!

Moodle is a "constant stopping experience," as they say;)

"These could," Kenneth.
Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door neha kakar -
Working with .htaccess files and server configurations can be tricky, but you did a great job troubleshooting and identifying the root cause of the problem. It's also great to see that the main site is now functioning as expected.

Gemiddelde van de beoordelingen:  -
Als antwoord op Andrew Kwabula

Re: Login not worfking, duplicate domain name in URL

door Philips habah -
Since Moodle cached information, you must easily separate the contents of /cache/ /localcache/ /muc/ from moodledata. Additionally, delete the site's cache and memory on your web page.

Did you restart the Apache service after adding or altering the certificate setup?

Do you have https:// in your secp file, or is it still just http://?

A test of the TLD "informative" using curl.

curl -I https://seotoolsystem.com/htaccess-redirect-generator/

makes this:
Gemiddelde van de beoordelingen:  -