• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1159
  • Last Modified:

.htaccess redirect with SSL without www

I am having difficulty writing a .htaccess redirect code that does the following two things:

1. redirects http to https
2. redirect www.domain.com to domain.com

Here are a few scenarios I am trying to fullfill

a.   domain.com  -->    https://domain.com
b.   http://www.domain.com/somepage.php    --->   https://domain.com/somepage.php
c.  www.domain.com   -->    https://domain.com


Thanks
0
dmehran
Asked:
dmehran
  • 2
1 Solution
 
ShaneJonesCommented:
This should work for you

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

The above redirects from http to https


Try that on its own first if it does not completely work try adding the following  

RewriteCond %{HTTP_HOST} ^www.domain.com                      
RewriteRule (.*) https://domain.com/$1 [R=301,L]

The above redirects www.domain.com to domain.com

Thanks

ShaneJones
0
 
dmehranAuthor Commented:
Shane,

Thanks for the solution. Your recipe  improved the situation quite a bit. However, the only situation that doesn't redirect properly is the URL:   https://www.bijoutique.net   (it doesn't redirect at all)

The following scenarios now get redirected successfully:

bijoutique.net  -->  https://bijoutique.net
www.bijoutique.net    -->   https://bijoutique.net
http://bijoutique.net   -->   https://bijoutique.net

Any ideas?
Thanks
0
 
ShaneJonesCommented:
Ok then .net was not inlcuded in your original question.

Where do you want that to redirect to? htttp://domain.com? Add these 3 lines too!

RewriteCond %{HTTP_HOST} ^www.domain.net
RewriteCond %{SERVER_PORT} 443
RewriteRule (.*) https://domain.com/$1 [R=301,L]
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now