0

I recently added a ssl certificate to my website. Now the problem is that some of the elements like images, fonts etc. are external content which is using http in "src=http://example.com/jpg" tag.

I know I can solve the problem by just replacing http with https in my elements tag but I have at-least 133 web-pages that will take a while to do it manually.

Is there any other alternative that I can use?

Can I use .htaccess for this problem?

note - I am using cpanel hosting

Joe
  • 4,877
  • 5
  • 30
  • 51
  • Sure there's a way; see [.htaccess redirect http to https](https://stackoverflow.com/questions/13376219/htaccess-redirect-http-to-https) for example. I wouldn't recommend it though, it would cause confusion. Replacing "http" by "https" would be much more straightforward, and maintainable. – Mr Lister Nov 10 '17 at 11:29
  • That is simply forcing HTTPs @MrLister - I think the OP is referring to links that they have coded into the site. So therefore requests would be loaded in HTTP even if the site is HTTPs and therefore cause an insecure connection. So really I think you need to manually change those links that you have coded in. – Joe Nov 10 '17 at 11:58
  • 1
    @Lag That's what I was referring to as well; my apologies if I was ambiguous. – Mr Lister Nov 10 '17 at 12:25
  • Yes, here I am talking the links that are coded into the site –  Nov 10 '17 at 13:01
  • 1
    In that case Arp, I'm sorry to tell you that the best thing for you to do is change them manually. Since they are coded in there is no real way to make a bulk change to this. Not through `.htaccess` anyway. Perhaps if you wrote a script to do this for you, then maybe you could automate it. – Joe Nov 10 '17 at 13:18
  • Actually the index file is written in PHP ( i .e index.php) and I am not sure how to do that in php –  Nov 10 '17 at 13:46

2 Answers2

0

.htaccess is not going to help you here as it is used for redirecting http to https in websites.

as you are using cpanel that means you dont have access to your root server therefore your only option is to manually convert http to https.

Damo
  • 12,840
  • 3
  • 51
  • 62
nadi
  • 1
  • 1
0

try this

RewriteEngine On

### WWW & HTTPS

# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

### WWW & HTTPS
drgdr
  • 16
  • 1