Redirect HTTP with www to HTTPS without www

Faal

Member
Jul 1, 2015
6
0
1
iran
cPanel Access Level
Website Owner
hi
Please help me
I need that my website is displayed only over SSL . Only
and Remove www
Only settings for file ".htaccess"

for all addresses and sub-folders

For example:
Code:
1: # Redirect HTTP without www to HTTPS without www
http://domain.com/
http://domain.com/wp-login.php

2: # Redirect HTTP with www to HTTPS without www
http://www.domain.com/
http://www.domain.com/wp-login.php

3: # Redirect HTTPS with www to HTTPS without www
https://www.domain.com/
https://www.domain.com/wp-login.php
end result: Remove www and display website over https

Code:
https://domain.com/
https://domain.com/wp-login.php
Please give three answers :

1: # Redirect HTTP without www to HTTPS without www

2: # Redirect HTTP with www to HTTPS without www

3: # Redirect HTTPS with www to HTTPS without www
 
Last edited by a moderator:

lldeepakll

Well-Known Member
May 20, 2012
85
3
58
India
cPanel Access Level
Root Administrator
Hi,

For your first two queries login to cPanel and click on Redirects option in Domains Section and

* Select Type Permanent (301)
* Select your domain (i.e. sample.com) (Leave the box empty after selecting domain from drop down)
* redirectes to --> https://domain.com
* Select "Redirect with or without www"

That's It.

Above settings will add following lines in .htaccess file.

RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/domain\.com\/" [R=301,L]


1: # Redirect HTTP without www to HTTPS without www

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ "https\:\/\/domain\.com\/" [R=301,L]


2: # Redirect HTTP with www to HTTPS without www


RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/domain\.com\/" [R=301,L]

3: # Redirect HTTPS with www to HTTPS without www

You mean https://www.domain.com ------> https://domain.com

Unfortunately I don't know any htaccess rule for this redirection. IMO, you should set php redirection for this type of redirection. Or someone else can provide you solution for this.

Thanks
 
Last edited by a moderator:

Faal

Member
Jul 1, 2015
6
0
1
iran
cPanel Access Level
Website Owner
Thanks
But not all-encompassing perspective
Code:
http://domain.com/wp-login.php
http://www.domain.com/wp-login.php
https://domain.com/wp-login.php
https://www.domain.com/wp-login.php
So what is the answer?

Please test, be sure to completely delete your browser's cache

thanks
but this Redirects for main pages is good :
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
but for wordpress in each is good :

Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
 
Last edited by a moderator: