-LAMP- 发表于 2013-2-7 01:59:09

我用.htaccess做了些什么

我用.htaccess做了些什么?

1、防图片盗链,减轻流量压力;

2、index.php 301转向到域名,有利于PR权重集中;

3、其它还不会,慢慢来……

我是如何做的?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{THE_REQUEST} ^{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.zfmoney.com/
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !zfmoney.com
RewriteRule .*\.(gif|jpg|png)$ -
</IfModule>

一些语句解释:

<IfModule mod_rewrite.c></IfModule>,判断mod_rewrite模块是否存在的,必须的。

RewriteEngine On,开启转向引擎。

RewriteBase /,转向基准目录。

RewriteCond %{REQUEST_FILENAME} !-f,如果文件存在,就直接访问文件,不进行下面的RewriteRule。

RewriteCond %{REQUEST_FILENAME} !-d,如果是这些后缀的文件,就直接访问文件,不进行RewriteRule。

RewriteRule ^(.*)$ /index.php/$1 ,伪静态设置,去除链接中的/index.php/。

RewriteCond %{THE_REQUEST} ^{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.zfmoney.com/
这两句作用是,实现带http://www.zfmoney.com/index.php 的域名定向为http://www.zfmoney.com/ 形式。

RewriteCond %{HTTP_REFERER} !^$ ,允许直接输入地址访问图片

RewriteCond %{HTTP_REFERER} !zfmoney.com ,允许该域名显示图片

RewriteRule .*\.(gif|jpg|png)$ - ,盗链网站不显示图片,直接显示红叉。

转自:http://www.zfnn.com/post/641.html#comment
页: [1]
查看完整版本: 我用.htaccess做了些什么