欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

陈的 htaccess

shiping1 的头像
htaccess文件(分布式配置文件)介绍
一、.htaccess文件用来对apache服务器进行配置,其所能实现的功能在主配置文件(http.conf)中均可实现
.htaccess文件(分布式配置文件)介绍
二、优点:
1、可针对不同的项目进行不同的配置
2、无需重启服务器即可进行配置
三、缺点、.htaccess文件会降低服务器的运行性能。
四、.htaccess运行条件
 在http.conf中AllowOverride不能为None
五、拒绝或允许用户访问:
1、拒绝所以用户访问:
order allow,deny
deny from all
2、允许所有人访问:
Allow from All
3、拒绝单个IP访问    deny from 192.168.105.201
4、拒绝整个IP段访问    
deny from 192.168.105.   
六、密码验证:
AuthName "please input password"    验证提示
AuthType Basic
AuthUserFile /var/www/html/chenyifei/.htpasswd.txt    验证文件
Require valid-user
2、密码文件生成
htpasswd  -cm  /var/www/html/chenyifei/.htpasswd.txt cyfei
追加密码:htpasswd  -bm  /var/www/html/chenyifei/.htpasswd.txt admin admin

七、错误信息显示:
ErrorDocument 403 "you can not visit this"  直接显示错误信息
ErrorDocument 403 /chenyifei/error403.html    转向错误提示文件
常见错误信息请求如下:
400 - Bad request 错误请求
401 Authorization Required需要验证
403 Forbidden禁止
404 Not Found找不到页面
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

八、防止列出所有目录    Options –Indexes
九、改变缺省首页    DirectoryIndex index.html index.php  login.php
十、伪静态
RewriteEngine on
RewriteRule index.html login.php  
 
RewriteEngine on
RewriteRule ^([a-zA-Z]+)\.html$    $1\.php [L]
RewriteRule ^([a-zA-Z]+)-([a-zA-Z]+)-([0-9]+)(.*)\.html$       $1\.php\?$2=$3  [QSA,L]

普通分类: