.htaccess http www or non www redirect to https

AccessDenied
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

RewriteEngine On

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]    

This is rules in .htaccess, urls like http://example.com/test, http://www.example.com/test doesn't redirect to https, www redirect to non-https address. http://example.com url redirected properly. What's wrong?

AccessDenied
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] 

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Rule moved to top and work's properly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

.htaccess redirect http/https www to https non-www

Redirect http to https and www to non-www in .htaccess

http to https redirect along with www to non-www in htaccess

htaccess redirect 301 https www to non www

Redirect Nginx HTTP/HTTPS www to non www

Redirect non-www(http) and www(http) to https://www

Redirect www. to non-www and redirect all http to https with .htaccess

Redirect non-www and www http requests to https://www

301 Redirect in htaccess from NON WWW to https://www with single redirect

How to redirect HTTPS non-www to HTTPS www using .htaccess?

So much trouble trying to redirect non-www and http to www and https in htaccess

Redirect multiple domains (http https www & non-www) to a new domain using htaccess

Redirect http to https with www using .htaccess

htaccess redirect to https://www

how to redirect www and non www to https for specific domain using htaccess

htaccess non-www to www while http to https and http://www to https://www

Redirect non-www to www for both http and https

IIS Redirect non-www to www AND http to https

Nginx Redirect HTTP to HTTPS and WWW to Non-WWW

Redirect http, non-www to https, with www for subfolder

Redirect non-www http request www domain with https connection

NGINX redirect http to https and www. to non-www

.htaccess - www to non-www & http to https & include trailing slash

htaccess and https/non-www to https/www

Nginx redirect all [http / www / https www] to [https non-www]

How to merge htaccess redirect by language function with www to non www and http to https? browsers return: err_too_many_redirects

rewrite/redirect http:// and http://www to https:// using htaccess

htaccess redirect to "https://www."

HTACCESS add WWW with HTTPS redirect