ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Éè¼ÆÀíÄî :: ÀûÓÃ.htaccess¿ØÖÆÍøÕ¾

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Éè¼ÆÀíÄî
ÀûÓÃ.htaccess¿ØÖ..
±ð¾ßÒ»¸ñµÄÍøÕ¾ÆÀ..
ÍøÕ¾Éè¼ÆÔ­Àí

ÀûÓÃ.htaccess¿ØÖÆÍøÕ¾


×÷Õß:Mitch Keeler ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2008-02-24 ä¯ÀÀ:3556 :: ::

Gain_More_Web_Site_Control_With_htaccessThere are many tools of the trade in the world of Web site development, but very few have as many good uses as your .htaccess file. What, you don't have one? I'll admit, information on these little darlings are confusing to some and hard to find. Hence the reason why we need an explanation of what it is and what it can do for you.

ÍøÕ¾¿ª·¢¹¤¾ßºÜ¶à£¬.htaccessÎļþÊǺܺÃÓõÄÒ»ÖÖ£¬ÄãÊÇ·ñÏëÓµÓÐÄØ£¿ÎÒÖªµÀ£¬ÓÐЩÈËÄÑÒÔÀí½âÕâ¸öÄÚÈÝ£¬²¢ÇÒºÜÄÑÕÒµ½¹ØÓÚÕâ¸öÎÊÌâµÄ˵Ã÷£¬ËùÒÔÕâÆªÎÄÕ½«»á½âÊÍ.htaccess ÎļþÊÇʲô£¬ÒÔ¼°ËüÓÐʲô×÷Óá£

Inside your Web hosting space, you know you have folders, HTML documents, and other things that make your Web site work. Think of this file as just another addition to the many thing you have inside there. It usually sits inside your root directory, such as "/public_html/" and has more than a few good uses. You might already have a .htaccess file in your root directory. If so, all you need to do is edit that one. Just remember that if it is in your root directory, that it will effect all folders and documents inside that directory. If you want to over ride that, then you will have to make a new .htaccess file inside the directory in question.

ÔÚÍøÕ¾ÐéÄâÖ÷»ú¿Õ¼äÖУ¬´æÔÚÎļþ¼Ð¡¢HTMLÎļþÒÔ¼°ÆäËü±£Ö¤ÍøÕ¾ÔËÐеÄÄÚÈÝ¡£Äã¿ÉÒÔ°ÑÕâ¸öÎļþÏëÏó³ÉÐéÄâÖ÷»úÄÚ²¿ÆäËüÎļþµÄÁíÒ»¸ö¸½¼ÓÆ·£¬Í¨³£Î»ÓÚ¸ùĿ¼ÖУ¨±ÈÈç"/public_html/"£©£¬ÓÃ;Óкܶࡣ¼ÙÈç¸ùĿ¼ÖÐÒѾ­´æÔÚÒ»¸ö.htaccessÎļþ£¬ÄãÐèÒª½øÐб༭¡£µ«Çë¼Çס£ºÈç¹ûÎļþ´æÔÚÓÚ¸ùĿ¼ÖУ¬Ð޸ĸùĿ¼»áÓ°Ïì¸ùĿ¼ÖеÄËùÓÐÎļþ¼ÐÒÔ¼°Îļþ¡£Èç¹ûÏ£ÍûÔÚ²»Ó°ÏìÆäËüÄÚÈݵÄÇé¿öÏÂÐ޸ģ¬ÄãÐèÒªÔÚ¸ùĿ¼Öн¨Á¢Ò»¸öеÄ.htaccessÎļþ¡£

For an example, if you want what is in the .htaccess file to effect everything but your "photos" folder then you would have to create a new .htaccess file inside your "photos" folder.

±ÈÈç˵£¬ÄãÏ£Íû.htaccessÎļþÓ°Ïì³ýÈ¥ÕÕÆ¬ÍâµÄÆäËüÄÚÈÝ£¬Äã¾ÍÐèÒªÔÚ“ÕÕÆ¬”Îļþ¼ÐÖн¨Á¢ÐµÄ.htaccessÎļþ¡£

How can you create one? Well, depending on the FTP program you are using it should be as easy as creating a new document, then renaming it .htaccess. Note that it has nothing coming before the dot. If you have anything in front of the dot, then it will not be read by the Web hosting server as a .htaccess file. The server will not know what to do with it.

ÈçºÎ´´½¨.htaccessÎļþÄØ£¿Äã¿ÉÒÔÀûÓÃFTP³ÌÐò£¬ºÜÈÝÒ×´´½¨³öÐÂÎļþ£¬È»ºóÖØÃüÃû.htaccess¡£Çë×¢Ò⣺ÎļþÃûÖеãµÄÇ°Ãæ²»ÄܳöÏÖÈκÎÄÚÈÝ£¬·ñÔòÐéÄâÖ÷»ú·þÎñÆ÷²»»á°ÑÆä¿´×÷ÊÇ.htaccessÎļþ£¬·þÎñÆ÷Ò²¾Í²»ÖªµÀÈçºÎ´¦ÀíÕâ¸öÎļþ¡£

If you want to create the file on your computer first, you should be able to right-click your desktop and select "New" then "Text Document". Then right-click that document on your desktop, and go to "Rename". Type in the new name as ".htaccess". Some programs might put the .txt extension on it automatically. All you have to do is go in to rename it again, and take that part off.

Èç¹ûÄãÏ£ÍûÊ×ÏÈÔÚ¼ÆËã»úÖд´½¨Õâ¸öÎļþ£¬ÄãÓ¦¸ÃÊ×ÏȽøÈë×ÀÃæ£¬Ñ¡Ôñ“н¨”£¬È»ºóµã»÷“Îı¾Îĵµ”£¬µã»÷×ÀÃæÉϵÄÎļþ£¬Ñ¡ÔñÖØÃüÃû£¬¼üÈë".htaccess"£¬ÓÐЩ³ÌÐò¿ÉÄÜ»á×Ô¶¯ÁôÏÂÀ©Õ¹Ãû.txt£¬ÄãÐèÒªÖØÐÂÃüÃûÎļþ£¬È»ºóÈ¥µô´Ë²¿·ÖÄÚÈÝ¡£

Another thing to remember is if you are creating the file on your own computer or uploading it from your own computer, make sure you are uploading it in ASCII mode, not binary. Most FTP programs do a pretty good job at auto-detecting how it should be uploaded, but if you run into a problem that is the first place I would check.

ÄãÐèҪעÒâµÄÁíÍâÒ»µãÊÇ£¬ÔÚµçÄÔÖд´½¨ÎļþÒÔºó£¬È·±£ÀûÓÃASC IIģʽ£¨·Ç¶þ½øÎ»µÄ£©ÉÏ´«¡£´ó¶àÊýFTP³ÌÐò»á×Ô¶¯¼à²âÉÏ´«Çé¿ö£¬µ«Èç¹û³öÏÖÎÊÌ⣬ÎÒ»áÊ×Ïȼì²éÕâ¸ö³ÌÐò¡£

Also, .htaccess files can only be created on a Linux based server running Apache. If you are not sure if you fall into that category login to your control panel your Web host provided you and snoop around in there. If you are still not sure, feel free to ask your Web host. That is what they are there for! You may need to CHMOD the htaccess file to 644 so the sever can execute the commands inside it.

.htaccess
ÎļþÖ»ÄÜÔÚÖ§³ÖLinuxµÄ·þÎñÆ÷Öд´½¨¡£Èç¹û²»È·¶¨ÊÇ·ñÊôÓÚ´ËÖÖÀàÐÍ£¬Äã¿ÉÒԵǼ¿ØÖÆÃæ°å£¬¼ì²éһϣ»Èç¹û»¹²»È·¶¨£¬Ñ¯ÎÊÐéÄâÖ÷»ú¹©Ó¦ÉÌ¡£Äã¿ÉÄÜÐèÒª¶¨ÒåhtaccessÎļþΪCHMOD644£¬ÕâÑù·þÎñÆ÷¿ÉÒÔÖ´ÐÐÎļþÖеÄÖ¸Áî¡£

Now you know how to create an empty .htaccess file. Now it is time to start filling it up with some easy to learn and useful commands. Think of each line you put into the .htaccess file as a command for the Web hosting server to do something. Here is an example of what I mean. Think of this as the content of your .htaccess file:

ÏÖÔÚÄã¿ÉÄÜÁ˽âÁËÈçºÎ´´½¨¿ÕµÄ.htaccessÎļþ£¬ÏÂÃæÓ¦¸ÃÔÚÎļþÖÐÌí¼ÓһЩÈÝÒ×ѧϰ¡¢Ê¹ÓõÄÖ¸Áî¡£.htaccessÎļþÖеÄÿһÌõÖ¸ÁÐéÄâÖ÷»ú·þÎñÆ÷¶¼±ØÐë×ñÑ­¡£ÄãµÄÎļþÄÚÈÝ¿ÉÒÔÈçÏ£º

  • Take out the trash£¨ÅųýÎÞÒâÒåÄÚÈÝ£©
  • Clean the sink£¨Çå¿ÕÄÚÈÝ£©
  • Mow the yard£¨Çåɨ£©
  • Rake the leaves£¨×îºóÇåÀí£©


Each are short commands you might do during your own day. A .htaccess file is much like giving the Web hosting server a to do list. Most commands in the .htaccess file are suppose to be on one line only. This is just the way that the server reads the information.

ÿһÌõÖ¸Áî¶¼¿ÉÄÜÊÇÄãÐèÒª×öµÄÄÚÈÝ¡£Ò»¸ö.htaccessÎļþÏ൱ÓÚΪÐéÄâÖ÷»ú·þÎñÆ÷ÌṩһÕÅÁÐ±í£¬ÎļþÖеĴó¶àÊýÖ¸ÁîÓ¦¸Ã³öÏÖÔÚÒ»ÐÐÖУ¬·þÎñÆ÷¾ÍÊÇÕâÑùÔĶÁÐÅÏ¢¡£

Another warning you might take in consideration is the ability to use the .htaccess file at all. Some Web hosts have banned it or banned it for certain uses because it causes stress and strain on the Web hosting server itself. Make sure you read through your Web host's frequently asked questions and acceptable use policy before moving forward. If they have something against it, then it should be in one of those two places.

ÄãÐèÒª¿¼ÂǵÄÁíÍâÒ»¸öÎÊÌâ¾ÍÊÇ£¬·þÎñÆ÷ÊÇ·ñ¿ÉÒÔÀûÓÃ.htaccessÎļþ¡£ÓÐЩÐéÄâÖ÷»ú²»Ö§³ÖÕâ¸öÎļþ£¬»òÕß²»Ö§³ÖÕâ¸öÎļþµÄijÏî×÷Óã¬ÒòΪÕâÑù»áÒýÆðÐéÄâÖ÷»ú·þÎñÆ÷µÄÔËÐÐѹÁ¦¡£ÀûÓÃÎļþ֮ǰ£¬Ê×ÏÈÔĶÁÐéÄâÖ÷»úʹÓÃÌõ¼þÒÔ¼°¸÷ÖÖ³£¼ûÎÊÌ⣬±ÜÃâÀË·Ñʱ¼ä¡£

Now that you have it, what can you do with it? That is another few articles all together. Some of the coolest things are password protection, error page redirects, and deny/allow IP address to access your Web site.

ÏÖÔÚÈçºÎÀûÓÃÕâ¸öÎļþÄØ£¿ÎÒÃÇ»áÔÚÒÔºóµÄÎÄÕÂÖнéÉÜ¡£ÎÒÃÇ»¹»á½éÉܵ½ÃÜÂë±£»¤¡¢³ö´íÒ³ÃæÉè¼ÆÒÔ¼°IPµØÖ·ÎÊÌâµÈµÈ¡£

ÆÀÂÛ (0) All