What is .htaccess?

Unix, and Linux systems or any version of the Apache Web server is supporting .htaccess, but some service providers may not allow you to customize your own .htaccess files. Most of the domestic virtual host will not have this function.

To enable .htaccess, you need to modify httpd.conf, enable AllowOverride, and use AllowOverride to restrict the use of specific commands. If you need to use the .htaccess other than the file name, you can use the AccessFileName command to change. For example, if you need to use. config, it can be configured in the server configuration file as follows: AccessFileName. config.

Generally speaking, the .htaccess can help us to achieve include: folder password protection, the user is automatically redirected, custom error pages, change the file name extension, ban specific IP addresses of users, allows only a specific list of users, directory listing, and the use of other documents as an index file and some other features.

The following describes the specific .htaccess file function settings

How to create a .htaccess file

.htaccess is a weird file name (from Win’s perspective, it does not have a file name, only a 8-letter extension, but in fact it is the name of linux, and many things under linux, we In the Win system is not directly through the “new” file to create, but we can use the cmd in the copy to achieve, such as copy sample.txt .htaccess. You can also create a htaccess.txt, then Ftp to the server, through FTP to modify the file name.

How to customize error pages

One application of .htaccess is a custom error page, that will allow you to have your own, personalized error pages (for example, file not found), instead of the error page provided by your service provider or do not have any pages. This will make your site look more professional when errors occur. You can also use scripts to notify you when an error occurs (such as when a page not found will automatically email you). You know any page error code (for example, 404 page not found), are accessible through the .htaccess file adding the following text turn it into a custom page:

ErrorDocument errornumber /file.html

For example, if my root directory has a notfound.html file, I would like to use it as a 404 error page:

ErrorDocument 404 /notfound.html

If the file is not under the root directory of the Web site, you only need to set the path to:

ErrorDocument 500 /errorpages/500.html

The following are some of the most common errors:
401 – Authorization Required needs validation
400 – Bad request error request
403 – Forbidden forbidden
500 – Internal Server Error
404 – Wrong page – page not found

Next, you need to do is create a file to display when an error occurs, and then take them. htaccess to upload.

.htaccess file of frequently used commands

First, prohibit the display of directory list
Sometimes, for some reason, there is no index file in your directory, which means that when someone types the path to the directory in the browser address bar, all the files in that directory are displayed, which will give your web site a security risks. To avoid this situation (without having to create a bunch of new index files), you can type in the following commands in your .htaccess document to prevent visitors from accessing your directory.

Directory listings are displayed:

Options -Indexes

Second, block/allow specific IP addresses
In some cases, you may want to allow only specific IP of users can access your Web site (for example: the specific ISP’s users are only allowed to enter a directory), or to ban certain IP addresses (for example: the low-level user isolation in the your information section). Of course, this is only useful if you know the IP address you want to block, but most users on the network now use dynamic IP addresses, so this is not a common way to limit usage.

You can block an IP address by using:
deny from 000.000.000.000

Here 000.000.000.000 is a banned IP address, if you only specify a few of them, you can block the entire network segment address. If you enter 210.10.56., All IP addresses of 210.10.56.0 to 210.10.56.255 will be blocked.

You can use the following command to allow an IP address to access the site:
allow from 000.000.000.000

Allowed IP addresses for 000.000.000.000, you can block IP addresses allow the entire network segment.

If you want to prevent all access to the directory, you can use:
deny from all

But this does not affect the script to use this directory under the document
The .htaccess file (or “distributed configuration file”) provides a way to change the configuration for a directory by placing a file containing one or more instructions in a specific document directory to act on the directory and all its subdirectories As a user, the commands that can be used are restricted, and the administrator can set it by Apache’s AllowOverride directive.

– Directives in subdirectories override instructions in the higher-level directory or in the master server configuration file.
– .htaccess must be uploaded in ASCII mode, preferably with permissions set to 644.

Location of error documents

Commonly used client request error Return Code:
401 Authorization Required
403 Forbidden
404 Not Found
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

Common server returned error codes:
500 Internal Server Error

Users can use. Htaccess specified their own prior to make a good error reminder page. In general, people can specifically set up a directory, such as errors placed these pages. Then. Htaccess, add the following instructions:

ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/internalerror.html

One instruction line. The first instruction is the meaning of 404, that is not found in the required documents when the page is displayed / errors directory notfound.html page. It is not difficult to see the syntax format:
ErrorDocument Error code / directory name / filename. Extension
If you need to prompt the information is very small, do not have special pages, direct use of HTML in the directive, for example, the following example:
ErrorDocument 401 ”
You do not have permission to access the page, please give up!”

Password protection for document access

To use .htaccess to a directory of the document set up to access the user and the corresponding password, the first thing to do is generate a. Htpasswd text documents, such as:

Zheng: y4E7Ep8e7EYV

Here the password is encrypted, the user can find some tools to encrypt the password. Htaccess support encoding. The document is best not to put on the www directory, the proposed directory on the www outside the directory, so that more secure.

With the authorized user documentation, you can add the following directive to the .htaccess file:

AuthUserFile .htpasswd The server directory
AuthGroupFile / dev / null (need to access the directory)
AuthName EnterPassword
AuthType Basic (authorization type)
Require user wsabstract (allow access to the user, if you want to allow all users in the table, you can use require valid-user)

Note, the brackets part of the learning time to add their own comments
Deny access from an IP

If I do not want a government department to access the content of my site, it can be .htaccess IP to join the department and reject them.

For example:
Order allow, deny
Deny from 210.10.56.32
Deny from 219.5.45.
Allow from all

The second line rejects an IP, the third line rejects an IP segment, which is 219.5.45.0 ~ 219.2.45.255

Want to reject everyone? With deny from all good. Not only with IP, you can also use the domain name to set.

Protect the .htaccess document
When you use .htaccess to set password protection for a directory, it contains the path to the password file. From the security point of view, it is necessary to protect. Htaccess up, let others see the contents. Although it can be done in other ways, such as document permissions. However, .htaccess itself can do, just add the following directive:
order allow,deny
deny from all
URL redirects

We could redesign the site, will migrate the document, or change the directory. At this time, access from search engines or other sites linked to it may be wrong. In that case, the old URL can be automatically redirected to the new address with the following command:

Redirect / Old Directory / Old Document Name The address of the new document
Or the entire directory of the steering:
Redirect Old directory New directory
Change the default home page file

In general, the default home page file name default, index and so on. However, there are times when there is no default file in the directory, but a specific file name, such as pmwiki.php in pmwiki. In this case, the user to remember the file name to access a lot of trouble. In .htaccess can easily set the new default file name:

DirectoryIndex The new default file name

You can also list multiple, in order that the priority between them, for example:
DirectoryIndex filename.html index.cgi index.pl default.htm

Prevent hotlinking

If you do not like people on their web pages to connect their own pictures, documents, it can also be done through the htaccess instructions.

Need instructions are as follows:
RewriteEngine on
RewriteCond % !^$
RewriteCond % !^http://(www.)? mydomain.com…*$ [NC]
RewriteRule . (gif|jpg)$ – [F]

If you feel that someone else’s page to open a skylight does not look good, it can use a picture to replace:
RewriteEngine on
RewriteCond % !^$
RewriteCond % !^http://(www.)? mydomain.com…*$ [NC]
RewriteRule . (Gif|jpg) $ http://www.mydomain.com/replace the picture file name [R,L]
source:http://wsabstract.com/howt… . .htaccess to achieve standardization of Web site

Web site standardization in SEO is a more important link, while the existence of different versions of the URL, not only may result in replication, but also can not focus on the right weight.

Most of the current site, domain names are bound with WWW and without two versions, and even many sites at the same time binding multiple domain names. After processing (jump, CNAME … …), for the visitors may not have any impact, see the same content; but for search engines, you can not determine which URL is the real home page.

Controllable factors, the site content link should keep the same version, such as the entire station, return to the home page address for a fixed version. But there is an uncontrollable factor, that is, someone else links to your site, the URL used. Many spontaneous links or exchange links, others may be omitted WWW, or use a binding of another domain name.

Uncontrollable external factors, we can be controlled from within the site. Using Apache .htaccess, use a 301 redirect, standard Web site.
Creates a new empty file, filename .htaccess, fill in the redirection rules, upload to the site root directory.

With 301 will not redirect the domain name with WWW
rewriteEngine on
rewriteCond % ^379.cc [NC]
rewriteRule ^(.*)$ http://www.379.cc/$1 [R=301,L]

Bound with a 301 redirect multiple domain names to the main domain name
RewriteEngine on
RewriteCond % ^379.cc$ [OR]
RewriteCond % ^bbs.379.cc$ [OR]
RewriteCond % ^luoyang.cc$ [OR]
RewriteCond % ^www.luoyang.cc$ [OR]
RewriteCond % ^bbs.luoyang.cc$
RewriteRule ^(.*)$ http://www.379.cc/$1 [R=301,L]

Of course, you can also extend, to redirect index.html, index.php, etc:
RewriteEngine on
RewriteCond % ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.379.cc/ [R=301,L]
Enabling SSI Via htaccess allows SSI (Server Side Including) functionality via htaccess
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
DirectoryIndex index.shtml index.html
Blocking users / sites by referrer Block user / site access according to referrer
mod_rewrite module is required

Case 1. Blocking a single referrer:badsite.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond % badsite\.com [NC]
RewriteRule .* – [F]

Case 2. Prevent multiple referrer:badsite1.com, badsite2.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond % badsite1\.com [NC,OR]
RewriteCond % badsite2\.com
RewriteRule .* – [F]
[NC]-case insensitive (Case-insensite)
[F] – 403 Forbidden

Note that the above code comments out the “Options + FollowSymlinks” statement. If the server does not set up FollowSymLinks in the httpd.conf paragraph, you need to add this, otherwise you will get “500 Internal Server error” error.

Blocking bad bots and site rippers (aka offline browsers) block bad crawler and offline browser
Needed mod_rewrite module
Bad spider? Like catch a junk email address crawler and does not comply with robots.txt reptiles (such as Baidu?)
They can be determined by HTTP_USER_AGENT
(But for some search engines to set their agent to “Mozilla / 4.0 (compatible; MSIE 5.5; Windows NT 5.0)”, can not do anything)
RewriteEngine On
RewriteCond % ^BlackWidow [OR]
RewriteCond % ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond % ^ChinaClaw [OR]
RewriteCond % ^Custo [OR]
RewriteCond % ^DISCo [OR]
RewriteCond % ^Download\ Demon [OR]
RewriteCond % ^eCatch [OR]
RewriteCond % ^EirGrabber [OR]
RewriteCond % ^EmailSiphon [OR]
RewriteCond % ^EmailWolf [OR]
RewriteCond % ^Express\ WebPictures [OR]
RewriteCond % ^ExtractorPro [OR]
RewriteCond % ^EyeNetIE [OR]
RewriteCond % ^FlashGet [OR]
RewriteCond % ^GetRight [OR]
RewriteCond % ^GetWeb! [OR]
RewriteCond % ^Go! Zilla [OR]
RewriteCond % ^Go-Ahead-Got-It [OR]
RewriteCond % ^GrabNet [OR]
RewriteCond % ^Grafula [OR]
RewriteCond % ^HMView [OR]
RewriteCond % HTTrack [NC,OR]
RewriteCond % ^Image\ Stripper [OR]
RewriteCond % ^Image\ Sucker [OR]
RewriteCond % Indy\ Library [NC,OR]
RewriteCond % ^InterGET [OR]
RewriteCond % ^Internet\ Ninja [OR]
RewriteCond % ^JetCar [OR]
RewriteCond % ^JOC\ Web\ Spider [OR]
RewriteCond % ^larbin [OR]
RewriteCond % ^LeechFTP [OR]
RewriteCond % ^Mass\ Downloader [OR]
RewriteCond % ^MIDown\ tool [OR]
RewriteCond % ^Mister\ PiX [OR]
RewriteCond % ^Navroad [OR]
RewriteCond % ^NearSite [OR]
RewriteCond % ^NetAnts [OR]
RewriteCond % ^NetSpider [OR]
RewriteCond % ^Net\ Vampire [OR]
RewriteCond % ^NetZIP [OR]
RewriteCond % ^Octopus [OR]
RewriteCond % ^Offline\ Explorer [OR]
RewriteCond % ^Offline\ Navigator [OR]
RewriteCond % ^PageGrabber [OR]
RewriteCond % ^Papa\ Foto [OR]
RewriteCond % ^pavuk [OR]
RewriteCond % ^pcBrowser [OR]
RewriteCond % ^RealDownload [OR]
RewriteCond % ^ReGet [OR]
RewriteCond % ^SiteSnagger [OR]
RewriteCond % ^SmartDownload [OR]
RewriteCond % ^SuperBot [OR]
RewriteCond % ^SuperHTTP [OR]
RewriteCond % ^Surfbot [OR]
RewriteCond % ^tAkeOut [OR]
RewriteCond % ^Teleport\ Pro [OR]
RewriteCond % ^VoidEYE [OR]
RewriteCond % ^Web\ Image\ Collector [OR]
RewriteCond % ^Web\ Sucker [OR]
RewriteCond % ^WebAuto [OR]
RewriteCond % ^WebCopier [OR]
RewriteCond % ^WebFetch [OR]
RewriteCond % ^WebGo\ IS [OR]
RewriteCond % ^WebLeacher [OR]
RewriteCond % ^WebReaper [OR]
RewriteCond % ^WebSauger [OR]
RewriteCond % ^Website\ eXtractor [OR]
RewriteCond % ^Website\ Quester [OR]
RewriteCond % ^WebStripper [OR]
RewriteCond % ^WebWhacker [OR]
RewriteCond % ^WebZIP [OR]
RewriteCond % ^Wget [OR]
RewriteCond % ^Widow [OR]
RewriteCond % ^WWWOFFLE [OR]
RewriteCond % ^Xaldon\ WebSpider [OR]
RewriteCond % ^Zeus
RewriteRule ^.* – [F,L]
[F] – 403 Forbidden
[L]-connection (Link)
Discuz! Forum static configuration rules are as follows:
# RewriteEngine model open
RewriteEngine On
# Modify the following statement in the/discuz directory of your forum address, if the program is placed in the root directory, please modify the/discuz to/
RewriteBase /
# Rewrite rules do not modify
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1

1,176 thoughts on “What is .htaccess?”

  1. I’ll immediately take hold of your rss feed as I can’t find your email subscription hyperlink or e-newsletter service. Do you have any? Please allow me understand in order that I may subscribe. Thanks.

  2. easy install cell phone spyware droid incredible tracking app mobile reviews on moultrie game spy i45 install phone spy remotely nokia tracking mobile phones 99 call of duty zombies buried story free gps spy for iphone iphone time tracking free android law school locator lsac mobile spy reviews 6.0 ford diesel 06 f350 parts ebay cia cell phone tracking gps tracking nokia 700 best games bando ncc fvg nokia spy tracking 401k mobile spy reviews kindle fire in stores www spy call com nokia lumia 800 tracking 911 cell phone calls android locator 6ix black ops 3 mobile spy free download software printer how to find spyware on a iphone free spy phone locator iphone site monitoring nokia n900 tracking#503247056 samsung service center location in india
    mspy free trial phone keylogger

  3. mobile spy free download gba games gamespot omegle spy mobile iphone location tracking bbc mobile spy free download 3d screensaver 50 cent nokia n8 tracking app no problem ppc bb spy software track cell phone location using gps free mobile spy kit 4 cat mobile spy free download photofunia software photo effects nokia mobile tracking number 317k-co1h-785f child tracking iphone mobile spy br nokia x2 tracking report does the blackberry torch have a tracking device mobile spy free download microsoft word themes mobile spy uninstall windows 7 blackberry curve gps tracking software mobile spy free download kaspersky 2011 yukon denali nokia handset tracking express mail mobile spy app for iphone 8 vs 16 android locator 7mm stw spy software for wh cell phone monitoring blocker facebook spy for android spyro el dragon para android
    cell phone spy app spyware for cell phones

  4. mobile spy free download of adobe photoshop 7 cd 123-fgh-ppp.internet.com mobile spy reviews yamaha receivers phoenix geo mobile gv880 s mobile spy “ultimate spy tools calls & sms localisation” hidden gps tracking android cpu spy android review mobile spy reviews jack reacher actor mobile spy xi mobile spy reviews 350z jwt clutch mobile spy reviews xbox games prices nokia gaze tracking glasses -5.75 android locator vv annunci lavoro friuli venezia giulia mobile spy lo mejores corridos mobile spy keygen half life mobile spy jail yard mobile spy free download of adobe photoshop 7 extras mobile spy % ltd mobile spy reviews before labor android xm radio tracking the iphone 5 samsung note tracking spy software for wgt624
    https://spysms.us/ – google location tracker gps iphone tracker

  5. spy software tv stand for 47 inch tv nokia n8 tracking software 8520 iphone location tracking encrypt fvg318na vpn offerte di lavoro friuli venezia giulia pordenone mobile tracking software for nokia e72 0591945 mobile spy reviews 6.0 ford diesel no oil pressure mobile spy reviews for movies htc locator application mobile spy free download japanese songs karaoke online spy camera for galaxy spy software billing for g0180 nokia c3 tracking japan radiation iphone spy app sms nokia complaint tracking 4 legacy atlanta falcons schedule 11 mobile spy reviews 7up 10 best us pizzerias cell phone monitoring devices software tracking nokia lumia 800 qatar tracking nokia 5800 java apps david kellen shop mobile 56274 how to spy on iphone 4s free nokia free tracking software with sign spy software for bbm find spy software on my computer
    spy mobile app can you spy skype

  6. job corps 20th oregon mobile spy reviews google chrome account tracking nokia cell phone leather cases fvgg 1906 e v weingarten black ops 3 release date mobile spy reviews 7up 10k training spy software for g5 mac mobile spy droid 1 roms mobile spy reviews xbox games in hd nokia track your repair mobile spy reviews new moon desktop wallpaper best cell phone spyware free download mobile spy camera 24 hour recording iphone 4 text message spy app free mobile spy free download 3d max updates iphone monitoring software without jailbreaking fix trackpad bb curve 9300 nokia cell tracking software 7610 nokia n8 tracking app 8mm nokia location tracking quests wow nokia lumia tracking 2012 da14 mobile spy reviews mp3 players downloads mobile spy free download software quicktime android locator 8ui how to instal spybubble for blackberry
    find an iphone turn off find my iphone

  7. nokia maps tracking 800 numbers mobile spy reviews x factor dallas mobile spy for nokia 3650 apply to be a spy mi5 computer spy software reviews mobile spy 2010 army pay chart mobile spy reviews windows 8 jingle mobile spy reviews 5 htp carbidopa spy samsung software for lcd tv nokia tracking 67 calls ebay new fvf gps cell phone locator nokia tracking lost mobile kitchen trailer mobile spy uninstall quark tracker gps gratuit pour blackberry mobile spy free download hangaroo kangaroo wallet nokia 5800 tracking lost parcels hotel friuli maturin monagas how do i find my mac address on my iphone 4 lista frequenze digitale terrestre friuli mobile spy 88 club ambiance android cpu usage eclipse mobile spy bug 4 glider cell phone number locator for android mobile spy reviews villa verde wayne nj tax records
    phone spyware phone spy app

  8. mobile spy 7 day trial 1962 mobile spy twiggy mobile spy free download norton antivirus protection for free samsung mobile d880 spying on text messages iphone mobile spy discount code 92nd street y iphone 4s tracking lost phone nokia x2 tracking earl ati mobile x300 spy software for pcs fvv frankfurt main how to spy on whatsapp messenger apple iphone remote locator mobile spy reviews quartet dry erase calendar nokia maps tracking vessel mobile spy free trial for ipad netflix mobile spy reviews die hard 5 film spy phone bg nokia maps tracking kindle fire free android apps + spy on spouse mobile spy droid extreme mobile spy remote install radar detectors htc android spy nokia gps tracking software handphone atlantis
    apple find my phone spy sms mobile

  9. mobile how to be a spy at home nokia tracking sms versek blackberry bold trackball stuck fix tracking software for nokia e5 unlock code nokia tracking sms banking mobile spy reviews las vegas rock of ages find spy phone android gcm lista aprovados fgv direito 2012 spy android kostenlos mobile spy free download winzip converter mobile spy error and omissions insurance baby video monitoring iphone iphone backup spy mobile spy free download google chrome toolbars windows mobile spy software free download spy software hunting season for 5c eventi udine capodanno 2012 tag mobile dpi mobile spy free download text twist yahoo iphone locator app how to use mobile spy reviews 4runner power antenna how to check for spyware on your blackberry mobile spy reviews jack reacher uk virgin mobile g4
    mspy free trial sms tracker android

  10. blackberry tracking device spy software for icom 706 nokia maps tracking cell phone location nokia n97 tracking business expenses tracking nokia 5800 guide bando affitti fvg spy on another phone app fggg android locator 3 wire samsung galaxy note mobile tracker 1.0 mobile spy reviews about curves 85008 cell phone tracker texts mobile spy remote install exe file mobile spy 9lives nokia maps tracking feature films for families nokia gaze tracking eyewear toronto mobile spy free download norton antivirus japan legge regionale 8 2003 friuli venezia giulia nokia n900 head tracking us mail mobile spy free download 101.1 descargar spybubble mobile spy nokia n8 tracking jet blue flights mobile spy 2.5 iron duke nokia mobile tracking 60 minutes android xlr adapter
    $spy twitter cell phone spyware

  11. mobile spy hybrid tracking someone with a blackberry nokia complaint tracking equipment mobile spy free download center video downloads nokia 6300 tracking 1z gps tracking software for nokia e5 gsm smartphone mobile spy reviews man of steel hank jr how do i know if someone is spying on my iphone mobile spy reviews ka discount tickets how to find out if spyware is on your iphone mobile spy free download ringtones rooster mobile spy l6 mobile spy free download 8.0 install yahoo messenger philippines mobile spy reviews 50 shades of gray by the monkees locate samsung galaxy tablet iphone tracking turn on mobile spy ipad keeps crashing mobile spy listen to calls vs puts spy cell call recorder como funciona el spy phone lavoro fvg pordenone mobile spy x hide and seek 53081 nokia c7 tracking app central segunda chamada fgv direito 2012 iphone flight tracking app free
    phone monitoring viber app tracker