'This webpage has a redirect loop' or 'The page isn't redirecting properly' with fresh installation


Today while testing out a fresh installation of Moodle 2.7 I came across the error ‘This webpage has a redirect loop’ due to which I was not able to enter the Moodle site as admin and can’t change anything even after clearing the browser cache and changing the browser also.

Redirect Loop Error
Redirect Loop Error

Doing a quick search on Moodle forums provide me few solutions which helped in resolving the error instead of going for a fresh install again, so I am reposting it here.
1. The first solution which worked for me was to commenting out the line number 451 of file yourmoodledirectory/admin/index.php file as:
2. and the second solution includes to Delete all the contents of Cache and Session directory in your moodledata directory and restart the browser.
For solution 1: https://moodle.org/mod/forum/discuss.php?d=230067#p1044795
For solution 2: https://www.lisenet.com/2014/fix-this-webpage-has-a-redirect-loop-moodle-v2-7/
Please post your solutions in the comments for the same problem if its different then the above two solutions.

Post Pages - Post Inline - WIRIS