php开源嘛
首页 | English | MySql数据库 | Php编程 | 建站杂烩 | 系统服务器 | 资源共享 | 专题 | 才桀网 | 支持论坛
  当前位置:主页>系统服务器>文章内容
虚拟主机中:.htaccess学习笔记
来源:网络 作者:本站整理 发布时间:2007-11-11  

虚拟主机中:.htaccess学习笔记

Apache的配置文件.htaccess是个难点,也是个重点。一直都没安下心来好好学学,甚至一直以为Redirect方法是属于mod_rewrite,用到的时候也都是糊里糊涂的。今天找到了一个很好的教程,一边学,一边写点心得。

updated: 不断修正一些小问题phpma.com

Source: Comprehensive guide to .htaccess

Officical reference: Directive Quick Reference

1 Introduction 介绍
文件名 .htaccess 属性 644 (RW-R–R–)phpma.com
htaccess会影响它所在目录下的所有子目录
注意大多数内容都要求保持在一行之内,不要换行,否则会引起错误

2 Error Documents 错误文档
Official document: ErrorDocument Directive

ErrorDocument code document
例子
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 404 http://yoursite/errors/notfound.html
ErrorDocument 401 “Authorization Required”
(注意之后内容如果出现的双引号需要转义为 \”)

常见HTTP状态码phpma.com

Successful Client Requests

200 OK
201 Created
202 Accepted
203 Non-Authorative Information
204 No Content
205 Reset Content
206 Partial Content

Client Request Redirected

300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy

Client Request Errors

400 Bad Request
401 Authorization Required
402 Payment Required (not used yet)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable (encoding)
407 Proxy Authentication Required
408 Request Timed Out
409 Conflicting Request
410 Gone
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

Server Errors

500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

3 Password Protection 密码保护
Official document: Authentication, Authorization and Access Control

假设密码文件为.htpasswd

AuthUserFile /usr/local/safedir/.htpasswd (这里必须使用全路径名)
AuthName EnterPassword
AuthType Basic

两种常见验证方式:phpma.com
Require user windix
(仅允许用户windix登陆)
Require valid-user
(所有合法用户都可登陆)

Tip: 如何生成密码文件
使用htpasswd命令(apache自带)

第一次生成需要创建密码文件
htpasswd -c .htpasswd user1

之后增加新用户
htpasswd .htpasswd user2

4 Enabling SSI Via htaccess 通过htaccess允许SSI(Server Side Including)功能
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes

DirectoryIndex index.shtml index.html

5 Blocking users by IP 根据IP阻止用户访问
order allow,deny
deny from 123.45.6.7
deny from 12.34.5. (整个C类地址)
allow from all

6 Blocking users/sites by referrer 根据referrer阻止用户/站点访问
需要mod_rewrite模块

例1. 阻止单一referrer: badsite.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC]
RewriteRule .* - [F]

例2. 阻止多个referrer: badsite1.com, badsite2.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsite2\.com
RewriteRule .* - [F]

[NC] - 大小写不敏感(Case-insensite)
[F] - 403 Forbiddenphpma.com

注意以上代码注释掉了”Options +FollowSymlinks”这个语句。如果服务器未在 httpd.conf 的 段落设置 FollowSymLinks, 则需要加上这句,否则会得到”500 Internal Server error”错误。

7 Blocking bad bots and site rippers (aka offline browsers) 阻止坏爬虫和离线浏览器
需要mod_rewrite模块


(阅读次数:

共2页: 上一页 1 [2] 下一页
上一篇:MySQL和SQL Server的安全性分析   下一篇:站长:你了解网站策划的几个要点吗?
[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论
  热点文章
·Linux配置web服务器全攻略
·Linux系统下Apache服务器设置与
·win中整合配置PHP和MySQL经典教
·Apache日志分析工具--AWStats安
·Apache中httpd.conf文件配置详解
·Linux嵌入式开发环境的简单介绍
·Linux系统下PHP服务器安全配置技
·Apache+Tomcat负载平衡设置方法
·Linux网络基本网络配置方法介绍
·配置Apache服务器并且设置DNS
·Linux系统Apache用户授权和访问
·Apache伪静态html(URL Rewrite)
  相关文章
·设置Apache中禁止以目录方式访问
·设置Apache服务器的用户验证...
·Linux系统下的FTP服务器配置技巧
·Apache中httpd.conf文件配置详解
·httpd.conf中的写入Apache中来禁
·怎样清理Linux系统中不需要的文
·Apche服务器日志系列(一):访问
·Apche服务器日志系列(二):错误
·Apche服务器日志系列(三):定制
·Apche服务器日志系列(四):日志
·Apche服务器日志系列(五):高级
·怎样将cookie用于Apache用户管理

关于我们 | 本站声明 | 友情连接 | 诚邀加盟 | 网站地图
版权Power by DedeCms   技术支持QQ =>> 罗江游鱼   Jacking  后台登陆
Copyright @ 2007 公司地址:柳州市东环路268号 邮编:545006 电话:15920389818 桂ICP备07006725号