htaccess介绍和使用方法(3)

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

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


where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range.

被允许的IP地址则为000.000.000.000,假如您只指定其中1或2个代码组,您能够允许整个区域的地址。

If you want to deny everyone from accessing a directory, you can use:

假如您想阻止任何人访问该文档目录,您能够使用:

deny from all
but this will still allow scripts to use the files in the directory.

但这将仍然允许脚本程式使用这个目录下的文档。

Alternative Index Files 替代的index文档

You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!

也许您不想一直使用index.htm或index.html来作为目录的索引文档,例如您的站点使用PHP文档,您会想使用 index.php来作为该目录的索引文档。当然也不必局限于“index”文档,假如您愿意,您尽管使用foofoo.balh来作为您的索引文档!

Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).

替代的索引文档能够排成一个列表,服务器会从左至右进行寻找,看看哪个文档在真实的目录中存在。假如一个也很难找到,他将会把目录清单显示出来(当然除非您关闭了显示目录文档清单)。

DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm
Redirection 重新指向

One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:

.htaccess其中一个极其有用的功能,就是将请求重新指向站内或站外的不同文档。当您改变了一个文档名称时但仍然想让用户仍然能够用旧链接找到他,这个时候此功能将变得极其有用。另一个应用(我发现的很有用的)是重新指向一个长URL,例如在我的时事信息中,我能够使用一个很简短的URL来指向我的联合链接。以下是个重新指向特定文档的例子:

Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz
In this above example, a file in the root directory called oldfile.html would be entered as:

上述的例子中,访问在root目录下的名为oldfile.html能够键入:

/oldfile.html
and a file in the old subdirectory would be entered as:

访问一个旧次级目录中的文档能够键入:

/old/oldfile.html
You can also redirect whole directoires of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:

您也能够使用.htaccess将整个网站的目录都做重新指向,假如您的网站上有一个名为olddirectory的目录,并且您已在一个新网站http://www.newsite.com/newdirectory/上建立了和上相同的文档,您能够将旧目录下任何的文档做一次重新指向而不必一一声明:

Redirect /olddirectory http://www.newsite.com/newdirectory
Then, any request to your site below /olddirectory will bee redirected to the new site, with the
extra information in the URL added on, for example if someone typed in:

这样,任何指向到站点中/olddirectory的请求都将被重新指向新的站点,包括附加的额外URL信息。例如有人键入:

http://www.youroldsite.com/olddirecotry/oldfiles/images/image.gif
They would be redirected to:

请求将被重新指向到:

http://www.newsite.com/newdirectory/oldfiles/images/image.gif
This can prove to be extremely powerful if used correctly.

假如正确使用,本功能将极其强大。

Part 3 – 密码保护

Introduction 介绍

Although there are many uses of the .htaccess file, by far the most popular, and probably most useful, is being able to relaibly password protect directories on websites. Although JavaScript etc. can also be used to do this, only .htaccess has total security (as someone must know the password to get into the directory, there are no 'back doors')

尽管有各种各样的.htaccess用法,但至今最流行的也可能是最有用的做法是将其用于网站目录的可靠的密码保护。尽管JavaScrip等也能做到,但只有.htaccess具备完美的安全(即访问者必须知晓密码才能够访问目录,并且绝无“后门”可走)。

The .htaccess File

Adding password protection to a directory using .htaccess takes two stages. The first part is to add the appropriate lines to your .htaccess file in the directory you would like to protect. Everything below this directory will be password protected:

标签:

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

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

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