.htaccess

Online Tester

https://htaccess.madewithlove.be/

Document

  1. https://lesca.me/archives/htaccess-rewrite.html
  2. https://lesca.me/archives/htaccess-appendix.html#htaccess_regex

For CodeIgniter:

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|assets|uploads|stage|thumbs|$)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Note! “?” after “index.php” is must!!

https://ellislab.com/forums/viewthread/234634/

Rewrite rule for subfolders:

http://case.wikirex.com/vic/luna

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|assets|uploads|thumbs|$)
RewriteRule ^(.*)$ vic/luna/index.php?/$1 [L,QSA]

Reference:

Multiple Conditions:

RewriteEngine on

#Relation between multiple conditions is "and"

#Request URI that match start from '/member(annything)'
RewriteCond %{REQUEST_URI} ^/member.*$
#Request URI that doesn't match start from '/member/internship(with/without "/")'
RewriteCond %{REQUEST_URI} !^/member/internship(/)?$
#Redirect to root folder
RewriteRule ^(.*)$ / [R=302,L]

RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|assets|uploads|thumbs|$|demo|img|event)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Reference:

  1. https://www.stormconsultancy.co.uk/blog/development/code-snippets/redirect-entire-site-with-htaccess-but-exclude-one-or-more-directories/
  2. https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
  3. http://stackoverflow.com/questions/18964045/htaccess-redirect-all-domain-except-two-files

Redirect entire domain to another URL:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)wiib\.com\.tw(\\*)$ [NC]
RewriteRule ^(.*)$ http://bit.ly/2hoURm2 [L,R=302]

Redirect visitors by IP address

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^124\.155\.174\.5$
RewriteCond %{REMOTE_ADDR} !^61\.218\.44\.79$
RewriteCond %{REMOTE_ADDR} !^60\.250\.226\.11[0-4]$
RewriteRule .* https://www.google.com/ [R=301,L]