Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

.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

  1. Open Notepad
  2. Copy and paste code below
  3. Click File
  4. Click Save As...
  5. After File name:, type .htaccess
  6. After Save as type:, select All Files
  7. Click Save
  8. Upload .htaccess to the root directory of your website

Scheme

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
FromTo
http://https://

Prefix

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
FromTo
www.mydomain.commydomain.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

acme.sh

Apache .htaccess

Apache Regular Expressions

Apache RewriteCond

Apache RewriteEngine

Apache RewriteRule

Apache RewriteRule Flags

HomeMenu