利用.htaccess控制网站

多试试:多试试-计算机技术与软件


http://www.68design.net/Web-Guide/Other-Guide/31031-1.html


There 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文件。有些虚拟主机不支持这个文件,或者不支持这个文件的某项作用,因为这样会引起虚拟主机服务器的运行压力。利用文件之前,首先阅读虚拟主机使用条件以及各种常见问题,避免浪费时间。

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值