自定义 RSS 链接

  1. # 自定义 RSS 链接
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine on
  4. RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
  5. RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
  6. RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.feedburner.com/catswhocode [R=302,NC,L]
  7. </IfModule>

去除 WordPress 分类链接中的“/category/

  1. RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

开启浏览器端缓存

  1. FileETag MTime Size
  2. <ifmodule mod_expires.c>
  3. <filesmatch "\.(jpg|gif|png|ico|css|js)$">
  4. ExpiresActive on
  5. ExpiresDefault "access plus 1 year"
  6. </filesmatch>
  7. </ifmodule>

拦截机器人垃圾评论

  1. RewriteEngine On
  2. RewriteCond %{REQUEST_METHOD} POST
  3. RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
  4. RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
  5. RewriteCond %{HTTP_USER_AGENT} ^$
  6. RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

开启维护模式

  1. RewriteEngine on
  2. RewriteCond %{REQUEST_URI} !/maintenance.html$
  3. RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
  4. RewriteRule $ /maintenance.html [R=302,L]

图片防盗链

(替换 mysite 为自己的网址和/images/notlink.jpg 为自己定制的防盗链声明图片)

  1. RewriteEngine On
  2. #Replace ?mysite\.com/ with your blog url
  3. RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
  4. RewriteCond %{HTTP_REFERER} !^$
  5. #Replace /images/nohotlink.jpg with your "don't hotlink" image url
  6. RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

阻止指定 ip 访问

  1. <Limit GET POST>
  2. order allow,deny
  3. deny from 200.49.176.139
  4. allow from all
  5. </Limit>

带 www 跳转不带 www 的

  1. <IfModule mod_rewrite.c>
  2. RewriteCond %{HTTPS} !=on
  3. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  4. RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  5. </IfModule>

不带 www 跳转带 www

  1. <IfModule mod_rewrite.c>
  2. RewriteCond %{HTTPS} !=on
  3. RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  4. RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  5. </IfModule>

禁止展开目录

  1. # 禁止展开网站目录
  2. Options All -Indexes

强制 https 浏览

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteCond %{HTTPS} !=on
  4. RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  5. </IfModule>