« 马太效应 | Main | 利用.htaccess 实现空间防盗链 »

.htaccess 文件的应用

一.自定义404,401,等错误

1.首先建立一个名为: .htaccess
写入以下内容
ErrorDocument 401 /err401.html
ErrorDocument 402 /err402.html
ErrorDocument 403 /err403.html
ErrorDocument 404 /err404.html

其中,401,402,403,404代表错误类型,
后面的err401.html代表其相对应的页面,

2.分别建立名字为:
err401.html,err402.html.........
的文件,当出现对应的错误的时候,
就会指向对面的页面

3.传到根目录下,
也就是 public_html 目录下
一切就OK了

二. 去掉广告

建个文件名 .htaccess 的文件, 文件内容如下:
LayoutIgnoreURI *.php
LayoutIgnoreURI *.cgi
LayoutIgnoreURI *.htm
LayoutIgnoreURI *.html

将 .htaccess 上传至空间的 Public_html 目录下,即可去掉广告!

注意 *.* 这里..想去那种扩展名的文件,就写上那种文件的扩展名!
这个是最简单的方法,只要在根目录加这个文件,那么整个网站都不会有广告!

三、用.htaccess防盗链实例

SetEnvIfNoCase Referer "^http://0o.cn/" local_ref=1 Order Allow,Deny Allow from env=local_ref Allow from 127.0.0.1
记得把域名换成你的,如果你的是http://abc.abc.com的话,那域名的写法就是http://abc.abc.com/

四、通过.htaccess 把所有的 .php files 生成 .html

因为动态的文件.例如PHP,很难被SE收录.所以把PHP生成静态的HTML文件就容易被SE收录.只需要通过简单的.htaccess就能做到此效果.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index.html$ index.php [T=application/x-httpd-php,L]

五、屏蔽IP地址方法

部分允许.htaccess的虚拟空间中实现IP禁止

建立一个.htaccess文件,写入以下内容:

#The next line modified by DenyIP
order allow,deny
#The next line modified by DenyIP
#deny from all
allow from all

例如:

Order allow,deny
allow from all
deny from 61.129.81.101
deny from 61.170.212.
保存,退出
解释
deny from 61.129.81.48
是屏蔽61.129.81.48的地址
deny from 61.170.212.
是屏蔽61.170.212的网段地址

简单说明:

deny from 222. 禁止222.XXX.XXX.XXX 这整个网段对网站的访问
deny from 222.254. 禁止222.254.XXX.XXX 对网站的访问
deny from 222.254.214. 禁止222.254.214.XXX 对网站的访问
deny from 222.254.214.32 禁止222.254.214.32 对网站的访问

这样用类似于B类地址的形式来封IP,如果要封59.32.0.0到59.39.255.255所有的IP的话就要写8条deny语句,大家可以用deny from 59.32.0.0/13来减少书写量,这里最好用程序来实现,要不然数量多的话就很麻烦。

FTP上传到mainwebsite_html目录里
改名为.htaccess的文件,文件会自动消失
然后就生效了。
被屏蔽的地址访问网站会出现
Forbidden
You don't have permission to access / on this server.
------------------------------------------------------
Apache/1.3.22 Server at www.域名.com Port 80
没有被屏蔽的地址能够正常访问
需要修改的话,可以重复上述操作。

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on June 6, 2006 8:41 PM.

The previous post in this blog was 马太效应.

The next post in this blog is 利用.htaccess 实现空间防盗链.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.