我要投稿
投诉建议
首页
传统文化
武术天地
编程技术
好听音乐
养生中医
智慧人生
常用工具
写作园地
影视娱乐
php专栏
道德经专栏
您当前的位置:
首页
>
编程技术
.htaccess文件使用心得
时间:2021-07-27 11:12:31 来源:网络 编辑:本站 点击:
什么是 .htaccess 文件?
概述来说,htaccess 文件是 Apache 服务器中的一个配置文件,它负责相关目录下的网页配置。通过 htaccess 文件,可以帮我们实现:网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。
1
设置错误页面
ErrorDocument400 /error_pages/400.html
ErrorDocument401 /error_pages/401.html
ErrorDocument403 /error_pages/403.html
ErrorDocument404 /error_pages/404.html
ErrorDocument500 /error_pages/500.html
2
设置重定向
#从 old_dir 目录重定向到 new_dir 目录Redirect /old_dir/ http://www.yourdomain.com/new_dir/index.html
#把通过二级目录访问的请求301重定向到二级域名RedirectMatch301 /dir/(.*) http://dir.yourdomain.com/$1
3
禁止指定IP访问
#禁止 IP 为 255.0.0.0 和 123.45.6.区段的 IP 访问orderallow,denydeny from 255.0.0.0
deny from 123.45.6.
allow from all
4
禁止指定来源访问
#禁止从 otherdomain.com 和 anotherdomain.com 的来源访问RewriteEngineon# Options +FollowSymlinksRewriteCond %{HTTP_REFERER} otherdomain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} anotherdomain\.com
RewriteRule .* - [F]
5
文件防盗链
#从本站以外的域名访问图片,一律显示 feed.jpgRewriteEngineonRewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.yourdomain.com/feed.jpg [R,L]
6
禁用文件夹列表
#如果你的文件夹没有首页文件,服务器会显示文件列表,你可以设置不显示IndexIgnore *
#仅不显示 .zip/.jpg/.gif 格式的文件IndexIgnore *.zip *.jpg *.gif
7
设置文件夹首页
#防止显示文件夹列表,当访问文件夹时,服务器查找 index.html 为首页文件,如不存在依次向后查找DirectoryIndex index.html index.cgi index.php
8
设置媒体文件为可下载的而非播放
AddType application/octet-stream .mp3 .mp4
9
自定义 HTTP 报头
Header set X-Pingback "http://www.xxx.cn/xmlrpc.php"Header set article-by "xxx.cn"
10
设置文件过期时间 Cache Control
<IfModule mod_expires.c>
# 启用有效期控制ExpiresActiveOn# gif/png/jpg 有效期为1个月ExpiresByType image/gif "access plus 1 month"ExpiresByType image/png "access plus 1 month"ExpiresByType image/jpg "access plus 1 month"# js/css 有效期为1星期ExpiresByType text/javascript "access plus 1 week"ExpiresByType text/css "access plus 1 week"
</IfModule>
点赞
返回
发表评论
共有
条评论
用户名:
密码:
验证码:
匿名发表
栏目导航
●
|
传统文化
|
武术天地
|
编程技术
|
好听音乐
|
养生中医
|
智慧人生
|
常用工具
|
写作园地
|
影视娱乐
|
php专栏
|
道德经专栏
|
最新推荐
python内建函数大…
点击按钮(button)…
帝国cms网络视频引…
相关文章
栏目更新
栏目热门
友情链接
帝国CMS
b站视频解析
哔哩哔哩
5sing音乐
劝学网
易文言
php中文网
喜马拉雅
引用视频
代码段生成
道医书库
墨鱼部落格
妍婷姝专辑
中华武术
周易全文
星座123
好看视频
汉程测试
桃花仙人
b站解析(91666)
菜鸟教程
小甲鱼学习计划
太极剑视频
零基础学Python
零基础学Web
零基础学汇编
数据结构和算法
网易云课堂
小甲鱼答案
Python 标准库
360图书馆
天涯知识库
emmet
传智播客
21世纪视频
超星视频
我爱自学网
51cto学院
极客学院
外唐教程网
CSDN
千字文
小不点
emmet文档
emmet手册
HTML中文网
U钙网LOGO
w3cschool
博客园
找盘网
前沿视频
百度技术
百度智能
腾讯课堂
慕课网
邢帅教育
网易公开课
大学生自学网
千锋教育视频
教程之家
北风网
渡一教育腾讯课堂
渡一教育
小甲鱼python新视频
鱼C工作室
小甲鱼系列视频
摄图网
爱拍剪辑
爱剪辑
傲软压缩宝
Arctime字幕软件
字幕在线转换器
喜马拉雅音频提取
U盘安装盘制作
我爱卡
汉字五行
五行查询
卜易居
片库网
学堂在线
易通cms
太极拳师师
中医世家
抖音视频解析
快手视频解析
微博视频解析
斗鱼视频解析
虎牙视频解析
左岸抖音歌曲
北京深度矩阵网络
海南息垚
北京深度矩阵
腾牛网
96开发网
创金游戏库
逗游
逗游网
007游戏网
逗游红包游戏
TapTap
网站首页
|
关于我们
|
服务条款
|
广告服务
|
联系我们
|
网站地图
|
免责声明
|
代码运行
|
手机版
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
Powered by
家园网www.jy.wang
© 2021-2029