I recently came across an issue with my WordPress installation. It’s situated behind a load balancer where SSL is terminated. The load balancer takes HTTPS traffic, then forwards it as HTTP on port 80 to the wordpress server.
I was running issues with a redirect loop after installing wordpress. The solution was to add this bit of code to wp-config.php:
define('FORCE_SSL_ADMIN', true); if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
This solves the redirect loop issue but then I ran into a different problem. When I tried to sign into wp-admin I would get this message:
Sorry, you are not allowed to access this page.
After much digging I found this post which emphasizes that you must place that code BEFORE anything else in wp-config.php (except for the beginning PHP tag.) Success!
Nicholas… You’re the best! i spend so many hours trying to figure out what the problem was. Moving that line did the trick! Thanks buddy
Good to hear that this helped you. I’m glad this was useful for someone else!
You’re brilliant Nicholas! This resolved my same problem. Thanks so much.
OH MYYYYY LOORRRRRRRRRRRRRDDDDDDDDDDDDD
I’ve spent two hours with this issue and this is the answer! Just to clarify the code needs to go after <?php in wp-config.php. You have a typo saying its wp-admin
I’m glad this helped you out! Thanks for pointing out the typo. I’ve corrected it.
Hi Nicholas,
I am the admin of the WordPress website and everything seems to be working fine when i access the dashboard.
However when i access the website through the editor profile the editor does not seem to have permission to make changes on the page etc. I cant even access the dashboard as an Editor. I am sometime able to access the back end of certain pages, however after i make the changes and click update i get a message saying i do not have sufficient permission to make these changes. I wonder why this is happening. I dont get editor privileges. Same thing happens with Author and so on.
I have also added the ‘User Role Editor’ Plugin, but i still get that lack of permission message.
Does you have any thoughts on how this can be rectified?
I’m not sure what it could be. If everything works for the admin I’m inclined to think it’s some sort of permissions issue for the user. What if you make a brand new user with those permissions?
OMG !!
I struggled so much with this one !
I setup WP in docker and ran into a real nightmare :/
But this post helped me a lot !
🙂
Thank you !!!
I’m glad this helped! Merry Christmas!
For anyone who is trying to use docker on a vps and running into this problem I’m writing some keywords here so hopefully when you do a search you’ll find this page. You’ll also possibly get a redirect loop error.
Thank….
after 2days working on it.
happy now… ^_^
Oh man! Glad I saw your post before smashing my computer screen.
<3 <3 <3 <3
Thank you so much! I overcomplicated everything and wasted like 2 hours figuring that out!
I’m glad this helped!
THANK YOU! 😀
Thank you Very much SIR…. ill give five star for you.
very very nice,.. thanks
Thanks alot
direct great answer
This was the fix for me also for AWS Elastic Load Balancer in front of WordPress machines.
Lifesaver 🙂
After hours and hours (days even) trying to figure this out…
This is the solution.
Just moved the code from the bottom of the config to the top and boom.
Thanks a ton.
works!
Thank you! Thank you! Thank you! Thank you!
🙂
Thank you, thank you, thank you.
Tried everything from adding a new admin level user to disabling plugins (by renaming plugins directory), to changing file / directory permissions and even enabling beta WordPress installs. Nothing helped.
This tip solved the problem!!!!
YOU ROCKS BUDDY
Thank you! Thank you! Thank you! Thank you!
Where to add the code, at the end of the WP-Config.PHP or where ?
Thank you.
Holy shit, your the savior
Damn. this is the issue. Amazon Sail, Bitnami, wordpress.
Thank you for your post!!!
<3
You’re welcome, glad I can help!
OMG!!!!!!!!! THANK YOU!!! Just wasted 2 days on this problem!
Why the hell don’t they tell you to put it at the top in the official docs here: – https://wordpress.org/support/article/administration-over-ssl/#rewrite-rules-for-secure-host-optional
So glad this was helpful. I wonder the same thing!
Thank you so much, got stuck for hours with this !