Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Redirect Domains with WWW (Cpanel/WHM)

tdottdot Member

I'm having trouble setting up a config file so that if a domain is loaded as 'example.com' it will redirect to 'https://www.example.com'

I have rewrite rule to add TLS under all my accounts but obviously isn't the most efficient solution so I'd like to put it in a config (add www. and https://)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

How do I set it up?
https://documentation.cpanel.net/display/EA4/Modify+Apache+Virtual+Hosts+with+Include+Files

Comments

  • sanvitsanvit Member
    edited January 2018

    check out here : http://bfy.tw/GH8g

  • Simply edit your .htaccess file and put

     RewriteCond %{HTTPS} !=on
     RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]
    

    I hope this will work fine.

  • WSSWSS Member
    edited January 2018

    @Rayhan You might want to put a clause in that it doesn't appended www if it's already there..

    @Rayhan said:
    Simply edit your .htaccess file and put

    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]

    >

    I hope this will work fine.

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,NE,L]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,NE,L]
    

    There's a bit of duplication here, but this basically throws you to https://www. no matter where you're going, and sends a 301 which will give pagerank to https:// - possibly. It could be broken into a slightly more logical stanza, but this makes it easy enough to read.

  • Is that covered on MOZ? never dealt with redirects don't want it to affect the serp

  • tdot said: don't want it to affect the serp

    301 are fine, don't worry about that.

  • happybeehappybee Member, Host Rep
    edited January 2018

    Usually, this rule in .htaccess should do the trick -

    RewriteEngine on RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https\:\/\/www\.example\.com\/$1 [R,L]

    However, if you are using applications like WordPress or similar, you may have to look into its 'SiteURL' settings.

Sign In or Register to comment.