Skip to main content
replaced http://webmasters.stackexchange.com/ with https://webmasters.stackexchange.com/
Source Link

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty paththere's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (mostly copied from the linked Wikipedia article):

<If "-T %{HTTPS} && %{HTTP_HOST} = 'www.example.com'">
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</If>

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (mostly copied from the linked Wikipedia article):

<If "-T %{HTTPS} && %{HTTP_HOST} = 'www.example.com'">
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</If>

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (mostly copied from the linked Wikipedia article):

<If "-T %{HTTPS} && %{HTTP_HOST} = 'www.example.com'">
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</If>
added 82 characters in body
Source Link
Ilmari Karonen
  • 9.1k
  • 1
  • 25
  • 41

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (copiedmostly copied from the linked Wikipedia article):

<If "-T %{HTTPS} && %{HTTP_HOST} = 'www.example.com'">
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</If>

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (copied from the linked Wikipedia article):

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (mostly copied from the linked Wikipedia article):

<If "-T %{HTTPS} && %{HTTP_HOST} = 'www.example.com'">
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</If>
added 431 characters in body
Source Link
Ilmari Karonen
  • 9.1k
  • 1
  • 25
  • 41

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (copied from the linked Wikipedia article):

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

For your first two rewrites (non-www → www, http → https), the following rule should work:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent]

Just replace www.example.com with the actual canonical hostname of your site.

As for your third point, there's no need to add or remove trailing slashes from URLs with an empty path, since such URLs are treated as canonically equivalent by all standards-conforming HTTP clients (including browsers and search engines).

Ps. If you want your site to be always accessed over HTTPS, you'll probably also want to configure your web server to send the HTTP Strict Transport Security header. For example, in Apache you could do that with the following directive (copied from the linked Wikipedia article):

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Source Link
Ilmari Karonen
  • 9.1k
  • 1
  • 25
  • 41
Loading