Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Posts
    419
    Thanks
    52
    Thanked 1 Time in 1 Post

    Question How to redirect www.domain.com to domain.com?

    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

  • #2
    evo
    evo is offline
    waka Ionsurge
    Join Date
    Feb 2005
    Location
    United Kingdom
    Posts
    895
    Thanks
    5
    Thanked 12 Times in 12 Posts
    All you would need to do is create a htaccess redirect rewrite to take users from www to non www with ssl attached;

    Code:
    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.

  • Users who have thanked evo for this post:

    MrTIMarshall (08-12-2012)

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Posts
    419
    Thanks
    52
    Thanked 1 Time in 1 Post
    Quote Originally Posted by evo View Post
    All you would need to do is create a htaccess redirect rewrite to take users from www to non www with ssl attached;

    Code:
    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

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,777
    Thanks
    6
    Thanked 1,021 Times in 994 Posts
    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:
    Code:
    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.

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Posts
    419
    Thanks
    52
    Thanked 1 Time in 1 Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •