{"id":128,"date":"2004-11-12T19:49:55","date_gmt":"2004-11-12T11:49:55","guid":{"rendered":"https:\/\/www.azfar.my\/2004\/11\/node\/128"},"modified":"2017-03-29T01:49:39","modified_gmt":"2017-03-28T17:49:39","slug":"fun-with-htaccess","status":"publish","type":"post","link":"https:\/\/azfar.my\/home\/2004\/11\/fun-with-htaccess.php","title":{"rendered":"fun with htaccess"},"content":{"rendered":"<p>have you ever wonder one day you were designing your website and not satisfied with it? want to enhanced it a little bit? well, thats where htaccess comes in. here&#8217;s some trick you can do, provided that your webhosting, server or whatever support htaccess.<\/p>\n<p>1. &#8220;damn the bandwidth stealer. i want them go away.&#8221; &#8230;erm, someone said to me that once. people hotlinking stuff, mostly images from your website and you don&#8217;t want them to do that? you can get rid of them by using htaccess. here&#8217;s how.<br \/>\na) go to the path of your website.<br \/>\nb) edit (if you have the .htaccess file) or create a new file, naming it <b>.htaccess<\/b>.<br \/>\nc) put this into that file:<\/p>\n<div class=\"example\">RewriteEngine on<br \/>\nRewriteCond %{HTTP_REFERER} !^$<br \/>\nRewriteCond %{HTTP_REFERER} !^http:\/\/(www.)?azfarismail.com.*$ [NC]<br \/>\nRewriteCond %{HTTP_REFERER} !^http:\/\/219.93.80.77.*$ [NC]<br \/>\nRewriteRule .*[Jj][Pp][Gg]$|.*[Gg][Ii][Ff]$ https:\/\/www.azfar.my\/go_away.jpg<\/div>\n<p>(remember to change the ip and the url. the &#8220;go_away.jpg&#8221; file is showed to the bandwidth stealer website when they are trying to hotlinking from your site. change it to your desired image. you can also use a blank page and change the path at RewriteRule.)<br \/>\nd) save the file and upload it into your website.<br \/>\ne) test it &#038; now, hotlinkers begone!<\/p>\n<p>erm, here&#8217;s&#8230;<!--more--><\/p>\n<p>2. &#8220;my webhosting 404 error page sucks and ugly. i want to change it.&#8221; hey hey, relax. you can do it using htaccess. here&#8217;s how.<br \/>\na) edit your <b>.htaccess<\/b> file.<br \/>\nb) put this script into it:<\/p>\n<div class=\"example\">ErrorDocument 400 \/errordoc\/404.html<br \/>\nErrorDocument 401 \/errordoc\/401.html<br \/>\nErrorDocument 403 http:\/\/www.you.com\/403.html<br \/>\nErrorDocument 404 http:\/\/www.you.com\/403.html<br \/>\nErrorDocument 500 http:\/\/www.you.com\/403.html<\/div>\n<p>(change the path or the url according to your taste.)<\/p>\n<p>3. got some sensitive stuff you kept in a folder? wan&#8217;t to restrict them to exclusive people? here&#8217;s how.<br \/>\na) create a <b>.htpasswd<\/b> file and put your username and password. create it [<a href=\"http:\/\/www.desilva.biz\/apache\/pwdweb.html\" target=\"_blank\">here<\/a>]<br \/>\nb) put this in your <b>.htaccess<\/b> file:<\/p>\n<div class=\"example\">AuthType Basic<br \/>\nAuthName &#8220;Secret&#8221;<br \/>\nAuthUserFile \/path\/of\/your\/.htpasswd<br \/>\nrequire valid-user<\/div>\n<p>c) save everything and upload everything (e.g: .htaccess &#038; .htpasswd file) in the folder you want to restrict.<br \/>\nd) test it.<\/p>\n<p>4. have a file like this?: www.you.com\/lala.php?action=abc. want to shorten it? here&#8217;s how.<br \/>\na) put this in your <b>.htaccess<\/b> file:<\/p>\n<div class=\"example\">Redirect \/short.html http:\/\/you.com\/lala.php?action=abc<\/div>\n<p>5. using IIS webserver (internet information services)? wow, you&#8217;re using windows nt :roll:. there are currently several worms exploit problems with IIS server, they search out path problems in IIS that would allow them to run cmd.exe which is the NT dos shell. unfortunately when hitting your apache server the worm will be served a 404 page. this can take up a lot of bandwidth if a lot of worm threads are searching your sites. to stop these worms cold you can redirect their hits to an invalid host with the following code in your <b>.htaccess<\/b> file:<\/p>\n<div class=\"example\">RedirectMatch (.*)cmd.exe$ http:\/\/www.lalafake.cominvalid$1<br \/>\nRedirectMatch (.*)root.exe$ http:\/\/www.lalafake.cominvalid$1<br \/>\nRedirectMatch (.*).dll$ http:\/\/www.lalafake.cominvalid$1<\/div>\n<p>6. don&#8217;t have an access to a php settings? want to turn off register_global? put this in your <b>.htaccess<\/b> file:<\/p>\n<div class=\"example\">&lt;IfModule mod_php4.c&gt;<br \/>\nphp_flag register_globals off<br \/>\n&lt;\/IfModule&gt;<\/div>\n<p>7. want to password protect some file? here&#8217;s how:<br \/>\na) put this in your <b>.htaccess<\/b> file:<\/p>\n<div class=\"example\">&lt;Files secret.html&gt;<br \/>\n   &lt;Limit GET POST PUT&gt;<br \/>\n      require valid-user<br \/>\n   &lt;\/Limit&gt;<br \/>\n   AuthName &#8220;Secret File&#8221;<br \/>\n   AuthType Basic<br \/>\n   AuthUserFile \/path\/to\/your\/.htpasswd<br \/>\n&lt;\/Files&gt;<\/div>\n<p>b) make sure you already have the .htpasswd file! refer to the article above.<\/p>\n<p>there&#8217;s actually many more tips and tricks you can do with <b>.htaccess<\/b>, but this is the only thing i can give you. to sum it, i am lazy, find it yourself. he he he&#8230;okay, enjoy, have fun and happy experimenting&#8230;<\/p>\n<p>More info [<a href=\"http:\/\/httpd.apache.org\/docs\/2.0\/misc\/rewriteguide.html\" target=\"_blank\">here<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>have you ever wonder one day you were designing your website and not satisfied with it? want to enhanced it a little bit? well, thats where htaccess comes in. here&#8217;s some trick you can do, provided that your webhosting, server or whatever support htaccess. 1. &#8220;damn the bandwidth stealer. i want them go away.&#8221; &#8230;erm, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-tutorial"],"_links":{"self":[{"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":0,"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/posts\/128\/revisions"}],"wp:attachment":[{"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/categories?post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azfar.my\/home\/wp-json\/wp\/v2\/tags?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}