.htaccess
.htaccess, or hypertext access, is a file that allows directory-level configuration changes.
Changes by this file apply to the directory where it is located and all subdirectories. It does not have a file name, only a file extension. The leading dot designates it as a hidden file.
Instructions
- Open Notepad
- Copy and paste code below
- Click File
- Click Save As...
- After File name:, type .htaccess
- After Save as type:, select All Files
- Click Save
- Upload .htaccess to the root directory of your website
Scheme
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
From | To |
---|---|
http:// | https:// |
Prefix
RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
From | To |
---|---|
www.mydomain.com | mydomain.com |
Key
RewriteEngine - rewrite engine RewriteCond - rewrite condition RewriteRule - rewrite rule %{HTTPS} - hypertext transfer protocol secure %{HTTP_HOST} - hypertext transfer protocol host %{REQUEST_URI} - request uniform resource identifier ^ - start of string $ - end of string . - match any character ? - match previous character zero or one time * - match previous character zero or more times + - match previous character one or more times \ - escape next character (treat special character as normal character) () - group %0 - backreference to rewrite condition %N - backreference to rewrite condition group (1 <= N <= 9) $0 - backreference to rewrite rule $N - backreference to rewrite rule group (1 <= N <= 9) [L] - last [NC] - no case (case insensitive) [R] - temporary redirect [R=301] - permanent redirect