15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > Apache伪静态规则文件.htaccess的另类用法

Apache伪静态规则文件.htaccess的另类用法

时间:2024-03-02 13:35:01 | 来源:网站运营

时间:2024-03-02 13:35:01 来源:网站运营

Apache伪静态规则文件.htaccess的另类用法:

1、开启/关闭拼写检查(关闭后会区分大小写)

CheckSpelling On #开启

CheckSpelling Off #关闭

关闭拼写检查可以解决一下报错

2、禁止/只允许特定IP访问

(1) 禁止单个IP访问,例如192.168.1.1

Order Allow,Deny

Allow from all

Deny from 192.168.1.1

(2) 禁止IP段访问,例如192.168.1.0/24、192.168.0.0/16

Order Allow,Deny

Allow from all

Deny from 192.168.1

Deny from 192.168

(3) 只允许特定IP访问,例如192.168.1.1

Order Allow,Deny

Deny from all

Allow from 192.168.1.1

3、防止目录浏览

Options All -Indexes

4、自定义错误页面

ErrorDocument 403 /403.html

ErrorDocument 404 /404.html

ErrorDocument 500 /500.html

5、设置默认首页

DirectoryIndex 123.html

6、屏蔽恶意蜘蛛(User Agent)

SetEnvIfNoCase User-Agent "^Baidu" bad_bot

SetEnvIfNoCase User-Agent "^sogou" bad_bot

SetEnvIfNoCase User-Agent "^Bloghoo" bad_bot

SetEnvIfNoCase User-Agent "^Scooter" bad_bot

Deny from env=bad_bot

7、防盗链

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$ [NC]

RewriteCond %{HTTP_REFERER} !google.com [NC] #白名单域名,谷歌

RewriteCond %{HTTP_REFERER} !baidu.com [NC] #白名单域名,百度

RewriteCond %{HTTP_REFERER} !test.com [NC] #白名单域名,自己的域名添加上

RewriteRule .*/.(jpg|gif|png|jpeg)$ http://deny.com [R,NC,L] #不在白名单的访问跳转到特定url上

8、禁止访问特定目录,例如拒绝任何人访问abc目录

在abc目录下创建.htaccess,写入一下内容:

deny from all

9、http跳转到https

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

关键词:静态,规则,文件

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭