जब आप web application develop करते है तो एक फाइल सामने आती है .htaccess, इसका इस्तेमाल करके आप server की configuration file कर सकते है. आज इस आर्टिकल में हम आपको .htaccess फाइल क्या है और इसको कैसे इस्तेमाल करें? के बारे में बताने जा रहे है.
Read This -> Computer/Laptop में पासवर्ड कैसे सेट करें?
.htaccess फाइल क्या है और इसको कैसे इस्तेमाल करें?
.htaccess फाइल क्या है?
यह एक Apache Web Server software की configuration file है जिसकी मदद से आप Apache Web Server software के additional functionality और features के enable/disable कर सकते है.
Read This -> Computer Expert कैसे बने?
.htaccess को कैसे इस्तेमाल करें?
अगर आप .htaccess को इस्तेमाल करना चाहते है तो आप इसका नाम सिर्फ .htaccess रखना है और इसके अलावा आप इसे file.htaccess नहीं लिखना है. इस फाइल को आपको अपने एप्लीकेशन की main डायरेक्टरी में रखना है, जहाँ पर आपकी index फाइल होती है. इसकी सैंपल फाइल के बारे में बताने जा रहे है.
AuthName “Member’s Area Name”
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html
यह एक सैंपल है जिसको इस्तेमाल करके आप अपने apache को configuration कर सकते है.
Read This -> Pendrive के आइकॉन पर अपनी Photo कैसे सेट करें?
Example के लिए जैसे आप php application में pretty URL बनाना चाहते है तो आप नीचे दिए गए कोड को अपने .htaccess में डाल कर इस्तेमाल करें.
Pretty URL
RewriteEngine On RewriteRule ^([^/]*)/([^/]*)$ /index.php?user=$1&action=$2 [L]
Password Protection
AuthName "Member's Area Name" AuthUserFile /path/to/password/file/.htpasswd AuthType Basic require valid-user
Deny visitors by IP address
//deny specific url order allow,deny deny from 255.0.0.0 deny from 123.45.6. allow from all //allow specific url order allow,deny allow from 255.0.0.0 deny from all
Deny visitors by referrer
//To set-up block a single referrer, RewriteEngine on # Options +FollowSymlinks RewriteCond %{HTTP_REFERER} otherdomain\.com [NC] RewriteRule .* - [F] //To set-up block multiple referrers RewriteEngine on # Options +FollowSymlinks RewriteCond %{HTTP_REFERER} otherdomain\.com [NC,OR] RewriteCond %{HTTP_REFERER} anotherdomain\.com RewriteRule .* - [F]
Hot link prevention techniques
//To set-up hot link prevention for '.gif', '.jpg' and '.css' files RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC] RewriteRule \.(gif|jpg|css)$ - [F] //To set-up hot link prevention for '.gif', '.jpg' files which displays alternate content RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC] RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/hotlink.jpg [R,L]
Blocking offline browsers and bad bots
RewriteEngine On RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:[email protected] [OR] RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR] RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR] RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR] RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR] RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR] RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR] RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR] RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR] RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR] RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR] RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR] RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR] RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR] RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR] RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR] RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR] RewriteCond %{HTTP_USER_AGENT} ^HMView [OR] RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR] RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR] RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR] RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR] RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR] RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR] RewriteCond %{HTTP_USER_AGENT} ^larbin [OR] RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR] RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR] RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR] RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR] RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR] RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR] RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR] RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR] RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR] RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR] RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR] RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR] RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR] RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR] RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR] RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR] RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR] RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR] RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR] RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR] RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR] RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR] RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR] RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR] RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR] RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR] RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR] RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR] RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR] RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR] RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR] RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR] RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR] RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR] RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR] RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR] RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR] RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR] RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR] RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR] RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR] RewriteCond %{HTTP_USER_AGENT} ^Wget [OR] RewriteCond %{HTTP_USER_AGENT} ^Widow [OR] RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR] RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR] RewriteCond %{HTTP_USER_AGENT} ^Zeus RewriteRule ^.* - [F,L]
Preventing access to your PHP includes files
## Enable Mod Rewrite, this is only required once in each .htaccess file RewriteEngine On RewriteBase / ## Test for access to includes directory RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /includes/ .*$ [NC] ## Test that file requested has php extension RewriteCond %{REQUEST_FILENAME} ^.+\.php$ ## Forbid Access RewriteRule .* - [F,NS,L]
Prevent access to php.ini
<FilesMatch "^php5?\.(ini|cgi)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch>
Preventing requests with invalid characters
RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&]+\ HTTP/ [NC] RewriteRule .* - [F,NS,L]
Check Out -> महापुरुषों की जीवन गाथा
Final Word
तो इस प्रकार आप .htaccess से अपने apache server की configuration कर सकते है. तो अब आपको पता लग गया होगा की .htaccess kya hai aur .htaccess ka istemaal kaise kiya jaata hai. अगर आपको इससे जुडी कोई अन्य जानकारी चाहिए या फिर किसी अन्य टॉपिक पर आप हमारा आर्टिकल चाहते है तो आप नीचे दिए गए कमेंट बॉक्स में कमेंट करके हमसे पूछ सकते है.