Images under /wp-content/uploads/ aren't visible over https (1 post)
Hi,
I've got an issue on my website where I cloned my wordpress from website.com to test.website.com and by default it works fine. (My test.website.com version is using 4.4 and lastest plugins, my website.com is using 4.3)
However, I am wanting to use SSL on the subdomain so when I add the following to the wp-config.php:
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
define('WP_HOME','https://test.website.com');
define('WP_SITEURL','https://test.website.com');
define('DOMAIN_CURRENT_SITE', 'test.website.com');
define('COOKIE_DOMAIN', 'test.website.com');
define('ADMIN_COOKIE_PATH', '/wp-admin/');
I would expect SSL to work correctly and it does once the small "issue" of mixed content warnings being fixed but that can easily be resolved via a search & replace plugin or via a SQL find and replace.
I've fixed the above and now I now run into the main issue where ALL images that are uploaded in the /wp-content/uploads/ directory are returning 404 not found errors but ONLY when they are coming over https, they show fine under http
The following shows can help explain:
https://test.website.com/wp-content/uploads/image.jpg = 404 (Not found)
http://test.website.com/wp-content/uploads/image.jpg = 200 (OK)
https://test.website.com/wp-content/image.jpg = 200 (OK)
http://test.website.com/wp-content/image.jpg = 200 (OK)
https://test.website.com/image.jpg = 200 (OK)
http://test.website.com/image.jpg = 200 (OK)
If I remove the .htaccess file from the uploads folder, it still doesn't resolve the issue... so it surely can't be .htaccess related, for reference here is my uploads .htaccess file:
# BEGIN Wordfence code execution protection
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
AddHandler cgi-script .php .phtml .php3 .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
# END Wordfence code execution protection
# BEGIN WishList Member Attachment Protection
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(fusion_slider_exports|revslider)/?(.*)$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|bmp)$
RewriteRule ^(.*)$ /index.php?wlmfile=$1 [L]
# END WishList Member Attachment Protection
As for the .htaccess under the main folder, I use a generic .htaccess file:
# 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
But, I do want to force https across this subdomain so I would usually use the following but while trying to fix this issue, I am just using a generic version.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.website\.com
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://test.website.com/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Bare in mind this test subdomain is pointing to /public_html/test/ where as my main wordpress is located in /public_html/
The .htaccess in /public_html/ looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# rewrite subdomains to separate folder
RewriteRule ^test/ - [L]
RewriteCond %{HTTP_HOST} !^www\.website\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.website\.com$
RewriteRule ^(.*)$ test/$1 [L]
# remove www from host
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Alternative (probably better force non-www and force https)
#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{HTTPS} !=on [OR]
# RewriteCond %{HTTP_HOST} !^website\.com$ [NC]
# RewriteRule ^ https://website.com%{REQUEST_URI} [R=301,L]
#</IfModule>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas how to make the images from the /wp-content/uploads/ actually work over https... I'd greatly appreciate some help getting this fixed.
About this post
- Posted
- Archived
- Score
- 3 · 100% up
- Kind
- Text
- ID
- 3yyszu
8 comments
Not sure, but one thought. When you cloned the site and changed all the URLs to include test, did you do a search and replace in the database? Do you need to do that again with https maybe?
Yes, I already mentioned that:
But that's not the issue, the issue is that the images are 404'ing when loaded via https, they work perfectly over http.
Just going to the image directly is impossible via https.
As I showed:
Cool. There's a bit more expertise in r/prowordpress that might be able to help.
Sounds like a puzzler. Here are a few random thoughts:
Are you testing with Chrome? It won't show the images if it doesn't like the SSL certificate.
What happens if you upload a new image using the WordPress media library under SSL? Is it visible?
Are you using a CDN or image optimization service?
Site caching?
To answer your questions:
I am testing in Chrome but also other browsers but regardless of this the certificate is fine, it works fine on website.com and most of the subdomain just not the images under wp-content/uploads
The same happens with new uploads
No image optimization or CDN
Site caching is default, so off.