.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
dmehranAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.