.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
HTTPS
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
FROM | TO |
---|---|
http:// | https:// |
NO-WWW
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