How can I redirect www to non www site?

.httaccess redirect for ssl and non-ssl www to non-www

  • I have an Apache CentOS (latest) site with subdomains, I want normal users using http and when using the shopping cart to use https; I use non-www, so I want to redirect all www to the non-www url as below; now the problem I'm having is the https ssl url; I have a single ssl cert (not a wild card) so I need all www to redirect to the non-www; but I get the page "This Connection is Untrusted", forcing users to except this cert or exit; after you except it, it will do the redirect; but not before, how can I fix this so they do not get that page? RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

  • Answer:

    If I understand you correctly: http://yourdomain.com -> no redirect http://www.yourdomain.com -> redirects to http://yourdomain.com https://yourdomain.com -> no redirect, works fine https://www.yourdomain.com -> Untrusted warning, then redirects to https://yourdomain.com Assuming I have understood you correctly this is the nature of SSL. If anyone tries to connect to your server using the "yourdomain.com" certificate at any hostname other than "yourdomain.com" you will get this error. So there is no way for someone to connect to https://www.yourdomain.com and not receive an error (unless you register a key for that... which is not what you wanted to do). More or less "working as intended" in this case. People who go to the wrong URL will get whined at until they go to the correct one.

user83395 at Server Fault Visit the source

Was this solution helpful to you?

Other answers

If you just need to support both your non-www and www domain names you can do that with one cert. Redirecting with htaccess won't work, you'll still get the "untrusted" error. http://bit.ly/oKWOe7

jakers

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.