Link to home
Start Free TrialLog in
Avatar of S Saxena
S SaxenaFlag for India

asked on

SSL Issue

Hello,

I just added SSL to my website. My site is a wordpress site. As my server was not enforcing the use of SSL, I added the redirect code to my .htaccess file. But after adding the redirect code, my wordpress admin dashboard does not open. When I remove the code from .htaccess file, the admin dashboard functions properly but my home page does not show https and security lock. It shows a small circle which shows not secure. All other pages of my site are properly showing https and security lock. Following is the redirect code I added to .htaccess file.

RewriteCond %{HTTP_HOST} witage\.net [NC] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.witage.net/$1 [R,L]

Open in new window


Can somebody help me on this.
Regards
Saxena
Avatar of Prabhin MP
Prabhin MP
Flag of India image

Hi,
Which web server are you using?
If you are using apache add the following code in apache config file for port 80.

RewriteEngine on
RewriteCond %{SERVER_NAME} =wwwdomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


if you are using nginx add this in port 80 server block


server {
    listen         80;
#    return 301 https://qa4.kpisoft.com/home;
    return 301 https://$host$request_uri;
}
Avatar of S Saxena

ASKER

Thanks Prabhin,

Do you want me to add this code to my .htaccess file? Sorry for asking this but I am a novice, so please forgive. I am using apache server.

Regrads
Saxena
Hi,
you can remove the code which you added before to redirect to https in .htacccess file.
You can add the code which i have given in virtual host file or 000-default.conf file.
Thanks Prabhin,

But I can't see any virtual host file or 000-default.conf file in my root directory or wordpress directory.
Regards
Saxena
it not in WordPress directory,
it in /etc/apache2/sites-available/      in Ubuntu
/etc/httpd/conf/       in centos



choose according to the environment.

I can help you if you can provide me with remote access.
Do you want temporary access to my cpanel?
If you can help me resolving this issue, I will be obliged as all other pages of my site are showing https and security lock except my home page.
Hi,
Please follow this link,

https://www.digicert.com/ssl-certificate-installation-apache-cpanel.htm
add mycode virtual host file.
Template I use, which also passes through QUERY parameters, if they occur.

<VirtualHost *:80>
   ServerName  www.WEBSITE
   ServerAdmin support@WEBSITE
   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
   RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [NC,L,R=301]
   Include logging.conf
</VirtualHost>

<VirtualHost *:80>
   ServerName  WEBSITE
   ServerAdmin support@WEBSITE
   RewriteEngine on
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301]
   Include logging.conf
</VirtualHost>

<IfModule mod_ssl.c>

   <VirtualHost *:443>

      ServerName  www.WEBSITE
      ServerAdmin support@WEBSITE

      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
      RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]

      Include logging.conf

      SSLEngine on
      SSLUseStapling on

      SSLCertificateFile    /etc/letsencrypt/live/WEBSITE/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/WEBSITE/privkey.pem

      # Enable HTTP Strict Transport Security with a 2 year duration
      Header always set Strict-Transport-Security "max-age=63072000; preload"

   </VirtualHost>

   <VirtualHost *:443>

      ServerName  WEBSITE
      ServerAdmin support@WEBSITE

      DocumentRoot /sites/OWNER/WEBSITE/TYPE

      <Directory /sites/OWNER/WEBSITE/TYPE>
          Options +Indexes +FollowSymLinks
          AllowOverride All 
          Require all granted
      </Directory>

      Include logging.conf

      SSLEngine on
      SSLUseStapling on

      SSLCertificateFile    /etc/letsencrypt/live/WEBSITE/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/WEBSITE/privkey.pem

      # Enable HTTP Strict Transport Security with a 2 year duration
      Header always set Strict-Transport-Security "max-age=63072000; preload"

   </VirtualHost>

</IfModule>

Open in new window


Keep in mind HSTS + 301s cache in browsers for an unspecified period of time, so you might try this template with following changes.

1) Change all 301 codes to 302.

2) Comment out Strict-Transport-Security directives.

3) Once everything is working, then revert.

Tip: Many CMSes continually rewrite .htaccess files (WordPress for example). Likely best to place this template in your Apache config file, rather than .htaccess file, as occasionally WordPress plugins (caching + security related), rearrange or break .htaccess files, which can require manual editing of .htaccess repeatedly to fix these problems.

Best to use Apache config files for this, to escape the travails of .htaccess modifications.
This template expects usage of LetsEncrypt SSL cert files to live in their default location.
Hi all,

Thanks for your help. My problem is solved. I am closing this question.
Regards
Saxena
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.