Online Tester
https://htaccess.madewithlove.be/
Document
- https://lesca.me/archives/htaccess-rewrite.html
- https://lesca.me/archives/htaccess-appendix.html#htaccess_regex
For CodeIgniter:
1 2 3 4 |
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
1 2 3 4 |
RewriteEngine on RewriteBase / RewriteCond $1 !^(index\.php|images|robots\.txt|assets|uploads|thumbs|$) RewriteRule ^(.*)$ vic/luna/index.php?/$1 [L,QSA] |
Reference:
- http://note.tc.edu.tw/857.html
- http://inspire.twgg.org/internet/host-setting/item/256-apache-htaccess-rules-introduced-in-rewritecond.html
- http://stackoverflow.com/questions/11654541/how-do-i-setup-codeigniter-htaccess-in-a-sub-folder
Multiple Conditions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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:
- https://www.stormconsultancy.co.uk/blog/development/code-snippets/redirect-entire-site-with-htaccess-but-exclude-one-or-more-directories/
- https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
- http://stackoverflow.com/questions/18964045/htaccess-redirect-all-domain-except-two-files
Redirect entire domain to another URL:
1 2 3 |
RewriteEngine On RewriteCond %{HTTP_HOST} ^(.*)wiib\.com\.tw(\\*)$ [NC] RewriteRule ^(.*)$ http://bit.ly/2hoURm2 [L,R=302] |
Redirect visitors by IP address
1 2 3 4 5 6 |
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] |
- Note: If rules of .htaccess is not updated, try to clear browser cache.
- https://stackoverflow.com/questions/8985502/htaccess-redirect-to-all-ips-but-mine