Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a full wordpress site to HTTPS

I'm trying to get a wordpress site to HTTPS, but everything I try gives me a redirect loop. I've edited the htaccess, I've set it in PHP, I've even downloaded a wordpress plugin to convert it, but every method gives me a redirect loop error. I know that something has to be redirecting my https to http, but I don't know what. Here is my .htaccess file without any of the HTTPS settings in it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

And here's the PHP I'm trying to use in the header php file to conver the page to HTTPS:

if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}
like image 546
Matthew Fournier Avatar asked Oct 20 '22 13:10

Matthew Fournier


1 Answers

You don't need a blanket redirect in .htaccess or in PHP. Go to Dashboard >> Settings and change your URLs to https. Then save permalinks.

You may want to find/replace any http URLs in post/page content, media URLs, etc, so you don't get redirects for those from http to https. Try interconnectit.com WordPress Serialized PHP Search Replace Tool

After https is working, use Firebug with Firefox, or use the developer tools in Chrome or Safari or IE to see if you are getting any "insecure content" errors from non-https URLs in any theme files.

You may need to change to a relative path for images in CSS files, i.e. background-image: url(http://example.com/themes/wp-content/theme/images/image.jpg) to background-image: url(images/image.jpg)

And, you may need to remove the http from absolute paths in php theme files, i.e. change 'http://example.com/image.jpg' to '//example.com/image.jpg'; that will allow your resources to default to https.

like image 67
markratledge Avatar answered Oct 22 '22 04:10

markratledge