Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Apache redirect www to non-www and HTTP to HTTPS

Discussion in 'General Discussion' started by Nirjonadda, Feb 14, 2018.

  1. Nirjonadda

    Nirjonadda Well-Known Member

    Joined:
    May 8, 2013
    Messages:
    599
    Likes Received:
    15
    Trophy Points:
    68
    cPanel Access Level:
    Root Administrator
    Please let me know that how to Apache redirect www to non-www and HTTP to HTTPS?

    Code:
    http://example.com
    http://www.example.com
    https://example.com
    https://www.example.com
    https://www.example.com/all-directory/sub-directory/
    To

    Code:
    https://example.com
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. rangka_kacang

    rangka_kacang Active Member

    Joined:
    Jan 31, 2018
    Messages:
    35
    Likes Received:
    3
    Trophy Points:
    8
    Location:
    Malaysia
    cPanel Access Level:
    Root Administrator
    Hello.

    Write the following to your .htaccess file. This will redirect all traffics from www. (and it's sub directories) with and/or without https to

    https:// yourdomain.com

    Code:
    RewriteEngine On
    
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    p/s I have not tested this yet as I'm currently on the move. The 301 redirect is to avoid crawl bots from getting drunk.

    Thank you.
     
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,749
    Likes Received:
    1,885
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Nirjonadda

    Nirjonadda Well-Known Member

    Joined:
    May 8, 2013
    Messages:
    599
    Likes Received:
    15
    Trophy Points:
    68
    cPanel Access Level:
    Root Administrator

    Yes are working but only not working one sub directories URL. Please let me know this issue.

    Code:
    https://www.mysite.com/xenforo/admin to https://mysite.com/xenforo/admin 
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,749
    Likes Received:
    1,885
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Assistance with customizing Mod_Rewrite rules isn't offered, but note you may find more user-feedback to this type of question on a website such as StackOverflow. Or, you may want to consult with a qualified system administrator if you need help customizing Mod_Rewrite rules and the user-feedback you receive is not sufficient. We provide a list of companies offering system administration services at:

    System Administration Services | cPanel Forums

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice