Question

I need help with rewrite rules.

So I want that these addresses:

http://domain.com
http://www.domain.com
https://www.domain.com

Redirect to:

https://domain.com

Can someone help me?

Right now I have rule:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

But it doesnt redirect https://www to https://
Was it helpful?

Solution

Place this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} www\.
RewriteRule ^ https://domain.com%{REQUEST_URI} [L,R=301,NE]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top