A file located in the root directory.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
ErrorDocument 404 /404.html
Redirect 301 /wp-login.php http://404.com/
Redirect 301 /xmlrpc.php http://404.com/
Redirect 301 /api.php http://404.com/
Redirect 301 /lequ.php http://404.com/
Redirect 301 /action.php http://404.com/
Redirect 301 /log_in.php http://404.com/
Error pages
ErrorDocument 401 /unauthorized.html
ErrorDocument 403 "Forbidden Error"
ErrorDocument 404 /page-not-found.html
ErrorDocument 500 http://www.example.com/server-error
Permanent Redirect
Redirect 301 /api.php http://404.com/
Force WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
Force Non-WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
Force https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Force https With JavaScript
var loc = window.location.href+'';
if (loc.indexOf('http://')==0){
window.location.href = loc.replace('http://','https://');
}
Disable Directory Browsing
Options -Indexes
Enable:
Options +Indexes
Block Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Block Access
RewriteEngine on
RewriteCond %{HTTP_REFERER} example\.com [NC]
RewriteRule .* - [F]
Block IP Address
Deny from 123.123.123.123