cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution
Highlighted

ssl redirect using a htaccess file not working

I just moved from classic hosting to cpanel. I have multiple domains. I recently purchased an ssl certificate for 5 sites.
Right now I have just one domain that I have live. It is listed on the certificate.
When I type in my browser the url starting with https, it is a secure site.
But, I can't get the redirect to work.


I used this code suggested by Godaddy.

 

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

 

I replaced the 2 locations in the code where it says coolexample with my domain name.
here is the actual code I used.

 

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?fundogphoto\.com
RewriteRule ^(.*)$ https://www.fundogphoto.com/$1 [R,L]

 

As far as I understand the .htaccess file should go in the domain directory folder , but it didnt work.

 

I have tried placing the .htaccess file in the domain directory folder of this website, both the public_html folder and the domain directory folder of the site, and placing it in just the public_html folder.
Cant get the site to redirect to https.

Maybe I have not filled out the code correctly.

 

Anyone have a solution for this.
Thanks in advance.

3 REPLIES 3
Moderator
Moderator

Re: ssl redirect using a htaccess file not working

Hi @photobeth, thanks for posting.

I was able to access your site and it redirected to HTTPS for me. Were you able to get this sorted out? If you're still having trouble, feel free to follow up with some more details on what you were seeing now or what you changed. If you did resolve this, it might be helpful to other Community members to let them know what you did.

 

Gary - GoDaddy | Community Moderator
24/7 Support | Check System Status
Solution

Re: ssl redirect using a htaccess file not working

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

 

The way Godaddy wrote this is wrong. The .htaccess file generated by their own system is like this.

 

rewriteengine on
rewritecond %{SERVER_PORT} 80
rewritecond %{HTTP_HOST} ^(www\.)?coolexample\.com
rewritecule ^(.*)$ https://www.coolexample.com/$1 [R,L]

Solution

Re: ssl redirect using a htaccess file not working

I am using wordpress template.

 

My original content inside the .htaccess was this:

 

# htaccess
# 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

 

My new content to force url for SSL redirect is:

 

# htaccess
# 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

# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^yourwebsiteurl\.com$ [OR]
RewriteCond %{SERVER_NAME} ^www\.yourwebsiteurl\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL

 

Note: replace yourwebsiteurl text with your domain name. It worked for me and I hope it should work for you too.