...

View Full Version : How to redirect www.domain.com to domain.com?



MrTIMarshall
08-11-2012, 09:56 PM
Hello,

I recently got an SSL Certificate for my domain.com without checking the 'www' box as recommended by my friend, however, if you enter the 'www.' to go to my website, a warning message will appear.

I am new to the SSL Certificate and I'm not sure what exactly it is for at this moment of time, whether or not all my pages should automatically make them go on 'https' version rather than the 'http' version?

If someone could help me a little and clear my mind I'd be very grateful.

Best Regards,
Tim

evo
08-11-2012, 11:08 PM
All you would need to do is create a htaccess redirect rewrite to take users from www to non www with ssl attached;


RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

I think that's all you need but I'm not sure if it can be simplified further as it has two rewrites there. One of the other members will be able to say for sure.

MrTIMarshall
08-12-2012, 12:07 AM
All you would need to do is create a htaccess redirect rewrite to take users from www to non www with ssl attached;


RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

I think that's all you need but I'm not sure if it can be simplified further as it has two rewrites there. One of the other members will be able to say for sure.

Thank you Evo, I did come across this a few times whilst searching for an answer, however, I don't know how to use this, where exactly does it go and how do I add it?

I am a complete beginner at server side things and one thing is leading to another....

Best Regards,
Tim

VIPStephan
08-12-2012, 01:33 AM
You would create a file called .htaccess (yes, starting with period) and put that in the web root directory of your server (i. e. the root directory of your site). I have a different rule than evo which I deem more universal as you don’t need to manually set the domain name:


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


I’m not a pro in regular expressions but so far this has worked well. It’s not addressing HTTPS but it can be added easily as in evo’s example but using the syntax for the domain from my example.

MrTIMarshall
08-12-2012, 02:59 AM
Okay, this never worked...

I thought this would be a solution to my problem as I am getting ssl_error_bad_cert_domain when using https://www. on my domain but not when I remove the www. - how do I fix this?

Example: https://www.tornhq.com//Countries/World.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum