htaccess介绍和使用方法

2008-02-23 08:21:10来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

.htaccess文档是很有用的,下面一篇介绍:

• Part 1 – Introduction介绍

• Part 2 - .htaccess Commande命令

• Part 3 - Password protection密码保护

Part 1 – Introduction介绍

Introduction 介绍

In this tutorial you will find out about the .htaccess file and the power it has to improve your website. Although .htaccess is only a file, it can change settings on the servers and allow you to do many different things, the most popular being able to have your own custom 404 error pages. .htaccess isn't difficult to use and is really just made up of a few simple instructions in a text file.

从本指南中,您能够学习到有关.htaccess文档及其功能,用以优化您的网站。尽管.htaccess只是个文档,但他能够更改服务器的配置,允许您做许多不同的事情,最流行的功能是您能够创建自定义的“404 error”页面。.htaccess 并不难于应用,只是在一个text文档中添加几条简单的指令而已。

Will My Host Support It? 我的主机支持他吗?

This is probably the hardest question to give a simple answer to. Many hosts support .htaccess but don't actually publicise it and many other hosts have the capability but do not allow their users to have a .htaccess file. As a general rule, if your server runs Unix or Linux, or any version of the Apache web server it will support .htaccess, although your host may not allow you to use it.

这可能很难用简单的答案来回答。许多主机支持.htaccess但实际上并不会明确声明,许多其他类型的主机有能力但并不允许他们的用户使用.htaccess文档。作为一般性的规则,假如您的主机使用Unix或Linux系统,或任何版本的Apache网络服务器,他一般来说是支持.htaccess的,尽管您的主机服务器可能不允许您使用他。

A good sign of whether your host allows .htaccess files is if they support password protection of folders. To do this they will need to offer .htaccess (although in a few cases they will offer password protection but not let you use .htaccess). The best thing to do if you are unsure is to either upload your own .htaccess file and see if it works or e-mail your web host and ask them.

您的主机是否允许.htaccess,很好的一个标志是他是否支持文档夹的密码保护。为此,他们将提供.htaccess支持(尽管少数情况下他们提供密码保护功能但不允许您使用.htaccess)。假如您不确定,最好的办法一是上传您自己的.htaccess文档看看是否有用,二是e-mail给您的主机服务商询问。

What Can I Do? 我该怎么做?

You may be wondering what .htaccess can do, or you may have read about some of its uses but don't realise how many things you can actually do with it.

您可能疑惑.htaccess到底能做些什么,或您可能曾知道他的一些功能但并不真正了解您实际到底能够用他来做多少事情。

There is a huge range of things .htaccess can do including: password protecting folders, redirecting users automatically, custom error pages, changing your file extensions, banning users with certian IP addresses, only allowing users with certain IP addresses, stopping directory listings and using a different file as the index file.

.htaccess能够做大量范围的事情,包括:文档夹密码保护、用户自动重新指向、自定义错误页面、变更您的文档扩展名、屏蔽特定的用户IP地址、只允许特定的IP地址、停止目录表连同使用其他文档作为index文档。

Creating A .htaccess File 创建一个.htaccess文档

Creating a .htaccess file may cause you a few problems. Writing the file is easy, you just need enter the appropriate code into a text editor (like notepad). You may run into problems with saving the file. Because .htaccess is a strange file name (the file actually has no name but a 8 letter file extension) it may not be accepted on certain systems (e.g. Windows 3.1). With most operating systems, though, all you need to do is to save the file by entering the name as:

创建.htaccess文档也许会给您带来几个问题。写文档很容易,您只需要在文字编缉器(例如:写字板)里写下适当的代码。然后,您可能会碰到保存文档的困难,因为.htaccess是个古怪的文档名(文档事实上没有文档名,只有一个由8个字母组成的扩展名),一些系统(例如windows 3.1)无法接受这样的文档名。在大多数的操作系统中,您需要做的是将文档保存成名为:

".htaccess"
(including the quotes). If this doesn't work, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program.

(包括引号)。假如这也不行,您需要将其命名为其他的名字(例如htaccess.txt),再将其上传到服务器上,此后您就能够利用FTP软件来重命名他了。

Warning 警告

Before beginning using .htaccess, I should give you one warning. Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won't work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: 一五一十谈IIS安全机制

下一篇: 系统启动时的软肋Winlogon