Jump to content
  • Redirect http to https - non www to www with .htaccess


     Forwarding from http to https with .htaccess, simply redirect from http to https. A website encrypted with an SSL certificate (https) only makes sense if visitors access your website via HTTPS. In the following we will show you how you can set up the forwarding and which variants are available.

     

    Forwarding from http to https without considering the subdomain (www.)
    To ensure that the website is automatically redirected to HTTPS when the website is accessed via HTTP, all you have to do is add the following code snippet to the .htaccess file of your web project:

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    
    RewriteCond% {SERVER_PORT}! ^ 443 $
    RewriteRule (. *) Https: //% {HTTP_HOST} / $ 1 [R = 301, L]
    
    </IfModule>

    The redirect now works as follows:
    http://www.rackarbiatch.com is redirect to > https://www.rackarbiatch.com
    http://rackarbiatch.com is redirect to > https://rackarbiatch.com

    In this example, however, the forwarding of the subdomain (www.) Is not taken into account. However, this can cause a problem with the indexing of the website by search engine bots, because the pages with both www. as well as without www. are accessible. Search engines can evaluate this as duplicate content or attempted spam. Therefore, we also recommend forwarding from  non www. on www.

     

    Automatic forwarding

    Forwarding from http to https with consideration of the subdomain (www.)
    So that the forwarding from http to https, as well as the forwarding from not www. on www. becomes active, you have to insert the following code snippet into the .htaccess file of your web project:

    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    
    RewriteCond% {HTTP_HOST}! ^ www.rackarbiatch.com $ [NC]
    RewriteRule ^ (. *) $ https://www.rackarbiatch.com/$1 [L, R = 301]
    
    RewriteCond % {SERVER_PORT}! = 443
    RewriteRule ^ (. *) $ https://www.rackarbiatch.com/$1 [R = 301, L]
    
    </IfModule

    >

    The redirect now works as follows:
    http://www.rackarbiatch.com is  forwarded to > https://rackarbiatch.com
    http://rackarbiatch.com is forwarded to > https://www.rackarbiatch.com
    https://rackarbiatch.com is forwarded to > https://www.rackarbiatch.com

    If you use the spelling without www. you can of course adjust the forwarding destination accordingly. To do this, you simply have to adjust the URL for "RewriteRule" and switch to the version without www. refer.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms & Condition