htaccess介绍和使用方法(2)
2008-02-23 08:21:10来源:互联网 阅读 ()
在使用.htaccess之前,我必须给您一些警告。尽管在服务器上使用.htaccess绝对不太可能给您带来任何麻烦(假如有些东西错了,他只是没效用罢了),但假如您使用Microsoft FrontPage Extensions您就需要小心些。FrontPage Extensions使用了.htaccess,因此您不能编辑他,加入您自己的信息。假如您需要(并不推荐,但是可能)您应该先从服务器上下载.htaccess文档(假如存在),之后在前面加上您的代码。
Custom Error Pages 自定义错误页
The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).
我想介绍的.htaccess第一个应用是自定义错误页面,这使得您能够拥有自己的、个性化的错误页面(例如很难找到文档时),而不是您的服务商提供的错误页或没有任何页面。这会让您的网站在出错的时候看上去更加专业。您还能够利用脚本程式在发生错误的时候通知您(例如我使用Free Webmaster Help的PHP脚本程式,当很难找到页面的时候自动e-mail给我)。
You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:
任何您知道代码的错误(像404很难找到页面),您都能够将其变成自定义页面,要做的只是在.htaccess文档里加入以下一段:
ErrorDocument errornumber /file.html
For example if I had the file notfound.html in the root direct
ory of my site and I wanted to use it for a 404 error I would use:
例如,假如我的根目录下有一个nofound.html文档,我想使用他作为404 error的页面:
ErrorDocument 404 /notfound.html
If the file is not in the root directory of your site, you just need to put the path to it:
假如文档不在网站的根目录下,您只需要把路径配置为:
ErrorDocument 500 /errorpages/500.html
These are some of the most common errors:
以下是一些最常用的错误:
401 - Authorization Required
400 - Bad request
403 - Forbidden
500 - Internal Server Error
404 - Wrong page
Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.
这样,您要做的只是生成一个错误显示文档,然后把他们上传。
Part 2 - .htaccess 命令
Introduction 介绍
In the last part I introduced you to .htaccess and some of its useful features. In this part I will show you how to use the .htaccess file to implement some of these.
上一部分中我已将您引入了.htaccess连同他的一些有用的功能,在这一部分里,我将向您演示如何应用.htaccess文档去实现这些功能。
Stop A Directory Index From Being Shown 停示显示目录索引
Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site.
有些时候,由于某种原因,您的目录里没有index文档,当然这样意味着假如有人在浏览器地址栏键入了该目录的路径,该目录下任何的文档都会显示出来,这造成了网站的安全威胁。
To prevent against this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown:
为了避免这种情况(而不必创建一堆的新index文档),您能够在您的.htaccess文档中键入以下命令,用以阻止目录索引的显示:
Options -Indexes
Deny/Allow Certian IP Addresses 阻止/允许特定的IP地址
In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certian directory) or you may want to ban certian IP addresses (for example, keeping disruptive memembers out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage.
有些情况下,您可能只想允许某些特定IP的用户能够访问您的网站(例如:只允许使用特定ISP的用户进入某个目录),或您想拦截某些特定的IP地址(例如:将低级用户隔离于您的信息面版外)。当然,这只在您知道您想拦截的IP地址时才有用,然而现在网上的大多数用户都使用动态IP地址,所以这并不是限制使用的常用方法。
You can block an IP address by using:
您能够使用以下命令拦截一个IP地址:
deny from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range.
被拦截的IP地址则为000.000.000.000,假如您只指定其中1或2个代码组,您能够拦截整个区域的地址。
You can allow an IP address by using:
您能够使用以下命令允许一个IP地址的访问:
allow from 000.000.000.000
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: 一五一十谈IIS安全机制
下一篇: 系统启动时的软肋Winlogon
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
