Forum Moderators: phranque
<link rel="stylesheet" href="//www.example.com/styles.css"> use relative paths for local files
Switching to SSLBTW - SSL is no longer used. It was replaced with TLS by the Internet Engineering Task Force [en.wikipedia.org]
Do I need to manually change all these urls to https on all my pages one at a time, or there is a smarter way (say, through htaccess)?
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} .(css|js|jpg|jpeg|png|gif)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] this might workI think the problem is that some browsers simply won't send in the request in the first place. If no request is received, no redirect can be sent.
between domainsThis is the rare case where host is what matters, not domain. The locations blog.example.com/ and assets.example.com/ may be the same domain, but they're different hosts--heck, they might even live on different servers--and as such can't be reached by relative links from one to another.
@csdude55 - file paths using HTTP will still display an error in the browser.
I think the problem is that some browsers simply won't send in the request in the first place. If no request is received, no redirect can be sent.
Can you use // with a hostname, though? I thought it was a subcategory of relative link: “match the hostname and also the protocol”.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} .(css|js|jpg|jpeg|png|gif)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
[edited by: phranque at 1:29 pm (utc) on Dec 4, 2018]
[edit reason] unlinked url [/edit]
// in variables.php or header.php
<?php
$home = 'https://www.example.com';
?>
// at the top of every page, assuming it's in PHP
<?php
include '/path/to/variables.php';
echo <<<EOF
<a href='$home/page.php'>Click</a>
EOF;
?> it is possible the browser (now or in the future) will simply not request them.
editing the code on all the pages is your best solution
editing the code on all the pages is your ONLY solution
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Note: your server may require different code RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] http://subdomain.mysite.com to https://subdomain.mysite.com) or I need to add a separate line for each sub-domain?
https://%{HTTP_HOST}Don’t do this. Requests for
# Replace 'www.example.com' with your domain name (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]