千万个美丽的未来,抵不上一个温暖的现在,每一个真实的现在,都是我们曾经幻想的未来!
Mar
12
一、Apache YOURLS Rewrite规则
1、安装在根目录下:
# BEGIN YOURLS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls-loader.php [L]
# END YOURLS
2、安装在子目录下
# BEGIN YOURLS
RewriteEngine On
RewriteBase /somedir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /somedir/yourls-loader.php [L]
# END YOURLS
3、使用非带www的域名
# BEGIN WithoutWWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourls\.org$ [NC]
RewriteRule ^(.*)$ http://yourls.org/$1 [R=301,L]
# END WithoutWWW
二、Nginx YOURLS Rewrite规则
1、安装在根目录下
location /
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
}
rewrite ^/([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 last;
}
2、安装在子目录下
location /dir/
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/dir/([0-9A-Za-z]+)/?$ /url/yourls-go.php?id=$1 last;
}
rewrite ^/dir/([0-9A-Za-z]+)\+/?$ /url/yourls-infos.php?id=$1 last;
rewrite ^/dir/([0-9A-Za-z]+)\+all/?$ /url/yourls-infos.php?id=$1&all=1 last;
}
1、安装在根目录下:
# BEGIN YOURLS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls-loader.php [L]
# END YOURLS
2、安装在子目录下
# BEGIN YOURLS
RewriteEngine On
RewriteBase /somedir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /somedir/yourls-loader.php [L]
# END YOURLS
3、使用非带www的域名
# BEGIN WithoutWWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourls\.org$ [NC]
RewriteRule ^(.*)$ http://yourls.org/$1 [R=301,L]
# END WithoutWWW
二、Nginx YOURLS Rewrite规则
1、安装在根目录下
location /
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
}
rewrite ^/([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 last;
}
2、安装在子目录下
location /dir/
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/dir/([0-9A-Za-z]+)/?$ /url/yourls-go.php?id=$1 last;
}
rewrite ^/dir/([0-9A-Za-z]+)\+/?$ /url/yourls-infos.php?id=$1 last;
rewrite ^/dir/([0-9A-Za-z]+)\+all/?$ /url/yourls-infos.php?id=$1&all=1 last;
}
Mar
11
WordPress
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
WordPress Mu
location /{
server_name_in_redirect off;
port_in_redirect off;
rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1;
rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
}
}
Drupal
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
Twip
location /{
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php last;
}
}
Typecho
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
Discuz
location / {
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
}
Discuz X
location / {
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
return 404;
}
}
Dabr
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
SaBlog
location / {
rewrite “^/date/([0-9]{6})/?([0-9]+)?/?$” /index.php?action=article&setdate=$1&page=$2 last;
rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last;
rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;
rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last;
rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;
rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
rewrite sitemap.xml sitemap.php last;
rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;
}
Xnote
location / {
if (!-e $request_filename) {
rewrite "^/([A-Za-z0-9\-]{4,20})$" /index.php?url=$1 last;
}
}
Status.net
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
PHP-Wind
location / {
rewrite ^thread-htm-tid-(\d+)-(.*).html thread.php?fid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html read.php?tid=$1 last;
rewrite ^commtopics-(.*)-(.*) thread.php?fid=$1&page=$2 last;
rewrite ^commtopics-(.*) thread.php?fid=$1&page=$2 last;
rewrite ^article-(.*)-(.*)-(.*).html read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*)-(.*).html read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*).html read.php?tid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html read.php\?tid=$1 last;
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
rewrite ^(.*)/u/([0-9]+)$ $1/u.php?uid=$2 last;
}
Bo-Blog
location / {
if (!-e $request_filename)
{
rewrite ^/post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?entryid=$1&page=$2&part=$3 last;
rewrite ^/page/([0-9]+)/([0-9]+)/?$ /index.php?mode=$1&page=$2 last;
rewrite ^/starred/([0-9]+)/?([0-9]+)?/?$ /star.php?mode=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=category_$1&mode=$2&page=$3 last;
rewrite ^/archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 last;
rewrite ^/date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=showday_$1-$2-$3&mode=$4&page=$5 last;
rewrite ^/user/([0-9]+)/?$ /view.php?go=user_$1 last;
rewrite ^/tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /tag.php?tag=$1&mode=$2&page=$3 last;
rewrite ^/component/id/([0-9]+)/?$ /page.php?pageid=$1 last;
rewrite ^/component/([^/]+)/?$ /page.php?pagealias=$1 last;
#Force redirection for old rules
rewrite ^/read\.php/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/$3/ permanent;
rewrite ^/index\_([0-9]+)\_([0-9]+)\.htm$ http://$host/page/$1/$2/ permanent;
rewrite ^/star\_([0-9]+)\_([0-9]+)\.htm$ http://$host/starred/$1/$2/ permanent;
rewrite ^/category\_([0-9]+)\.htm$ http://$host/category/$1/ permanent;
rewrite ^/category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/category/$1/$2/$3/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/$3/$4/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/$4/$5/ permanent;
#Filename alias
rewrite ^/([a-zA-Z0-9_-]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?blogalias=$1&page=$2&part=$3 last;
}
}
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
WordPress Mu
location /{
server_name_in_redirect off;
port_in_redirect off;
rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1;
rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
}
}
Drupal
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
Twip
location /{
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php last;
}
}
Typecho
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
Discuz
location / {
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
}
Discuz X
location / {
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
return 404;
}
}
Dabr
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
SaBlog
location / {
rewrite “^/date/([0-9]{6})/?([0-9]+)?/?$” /index.php?action=article&setdate=$1&page=$2 last;
rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last;
rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;
rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last;
rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;
rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
rewrite sitemap.xml sitemap.php last;
rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;
}
Xnote
location / {
if (!-e $request_filename) {
rewrite "^/([A-Za-z0-9\-]{4,20})$" /index.php?url=$1 last;
}
}
Status.net
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
PHP-Wind
location / {
rewrite ^thread-htm-tid-(\d+)-(.*).html thread.php?fid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html read.php?tid=$1 last;
rewrite ^commtopics-(.*)-(.*) thread.php?fid=$1&page=$2 last;
rewrite ^commtopics-(.*) thread.php?fid=$1&page=$2 last;
rewrite ^article-(.*)-(.*)-(.*).html read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*)-(.*).html read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*).html read.php?tid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html read.php\?tid=$1 last;
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
rewrite ^(.*)/u/([0-9]+)$ $1/u.php?uid=$2 last;
}
Bo-Blog
location / {
if (!-e $request_filename)
{
rewrite ^/post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?entryid=$1&page=$2&part=$3 last;
rewrite ^/page/([0-9]+)/([0-9]+)/?$ /index.php?mode=$1&page=$2 last;
rewrite ^/starred/([0-9]+)/?([0-9]+)?/?$ /star.php?mode=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=category_$1&mode=$2&page=$3 last;
rewrite ^/archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 last;
rewrite ^/date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=showday_$1-$2-$3&mode=$4&page=$5 last;
rewrite ^/user/([0-9]+)/?$ /view.php?go=user_$1 last;
rewrite ^/tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /tag.php?tag=$1&mode=$2&page=$3 last;
rewrite ^/component/id/([0-9]+)/?$ /page.php?pageid=$1 last;
rewrite ^/component/([^/]+)/?$ /page.php?pagealias=$1 last;
#Force redirection for old rules
rewrite ^/read\.php/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/$3/ permanent;
rewrite ^/index\_([0-9]+)\_([0-9]+)\.htm$ http://$host/page/$1/$2/ permanent;
rewrite ^/star\_([0-9]+)\_([0-9]+)\.htm$ http://$host/starred/$1/$2/ permanent;
rewrite ^/category\_([0-9]+)\.htm$ http://$host/category/$1/ permanent;
rewrite ^/category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/category/$1/$2/$3/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/$3/$4/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/$4/$5/ permanent;
#Filename alias
rewrite ^/([a-zA-Z0-9_-]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?blogalias=$1&page=$2&part=$3 last;
}
}
May
15
1、防盗链
Options +FollowSymlinks
#Protect against hotlinking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]
2、通过User Agents 禁止访问
#Block bad bots
SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Java.* [NC,OR]
SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]
SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]
SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]
SetEnvIfNoCase user-Agent ^Zeus [NC]
<limit get="" post="" head="">
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</limit>
3、重定向(禁止)所有访问,某些来源IP除外
ErrorDocument 403 http://www.domainname.com
Order deny,allow
Deny from all
Allow from 124.34.48.165
Allow from 102.54.68.123
4、SEO 友好 301 重定向
Redirect 301 /d/file.html http://www.domainname.com/r/file.html
5、自定义错误页面
ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php
6、禁止某些来源IP
allow from all
deny from 145.186.14.122
deny from 124.15
7、设置服务器管理员的默认邮箱地址
ServerSignature EMail
SetEnv SERVER_ADMIN [email protected]
8、禁用显示下载请求
AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov
9、保护特定的文件,禁止访问。
#Protect the .htaccess File
<files .htaccess="">
order allow,deny
deny from all
</files>
10、利用mod_deflate压缩文件
<ifmodule mod_deflate.c="">
<filesmatch .(js|css)$="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
11、添加Expires头
<filesmatch .(ico|pdf|flv|jpg|jpeg|png|gif|swf)$="">
Header set Expires "Wed, 21 May 2010 20:00:00 GMT"
</filesmatch>
12、设置默认页
#Serve Alternate Default Index Page
DirectoryIndex about.html
13、设置密码保护文件和目录
#password-protect a file
<files secure.php="">
AuthType Basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
</files>
# password-protect a directory
resides
AuthType basic
AuthName "This directory is protected"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
14、将老域名重定向新域名
#Redirect from an old domain to a new domain
RewriteEngine On
RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]
15、强制缓存
FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus 86400 seconds"
16、启用GZIP压缩相关文件
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
17、从URL中移除“category”
RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]
18、禁止目录浏览
Options All -Indexes
19、重定向WordPress的订阅到Feedburner
#Redirect wordpress content feeds to feedburner
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourfeed [R=302,NC,L]
</ifmodule>
20、禁止空Referrer访问内容
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
21、从URL中删除文件扩展名
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
22、将www.domain.com重定向到domain.com
#remove www from URI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
23、URL结尾添加/
#trailing slash enforcement
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !#
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301
24、将www.domain.com/xxx重定向到domain.com/xxx
# Redirect if www.yourdomain.com to yourdomain.com
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
Options +FollowSymlinks
#Protect against hotlinking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]
2、通过User Agents 禁止访问
#Block bad bots
SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Java.* [NC,OR]
SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]
SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]
SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]
SetEnvIfNoCase user-Agent ^Zeus [NC]
<limit get="" post="" head="">
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</limit>
3、重定向(禁止)所有访问,某些来源IP除外
ErrorDocument 403 http://www.domainname.com
Order deny,allow
Deny from all
Allow from 124.34.48.165
Allow from 102.54.68.123
4、SEO 友好 301 重定向
Redirect 301 /d/file.html http://www.domainname.com/r/file.html
5、自定义错误页面
ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php
6、禁止某些来源IP
allow from all
deny from 145.186.14.122
deny from 124.15
7、设置服务器管理员的默认邮箱地址
ServerSignature EMail
SetEnv SERVER_ADMIN [email protected]
8、禁用显示下载请求
AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov
9、保护特定的文件,禁止访问。
#Protect the .htaccess File
<files .htaccess="">
order allow,deny
deny from all
</files>
10、利用mod_deflate压缩文件
<ifmodule mod_deflate.c="">
<filesmatch .(js|css)$="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
11、添加Expires头
<filesmatch .(ico|pdf|flv|jpg|jpeg|png|gif|swf)$="">
Header set Expires "Wed, 21 May 2010 20:00:00 GMT"
</filesmatch>
12、设置默认页
#Serve Alternate Default Index Page
DirectoryIndex about.html
13、设置密码保护文件和目录
#password-protect a file
<files secure.php="">
AuthType Basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
</files>
# password-protect a directory
resides
AuthType basic
AuthName "This directory is protected"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
14、将老域名重定向新域名
#Redirect from an old domain to a new domain
RewriteEngine On
RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]
15、强制缓存
FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus 86400 seconds"
16、启用GZIP压缩相关文件
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
17、从URL中移除“category”
RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]
18、禁止目录浏览
Options All -Indexes
19、重定向WordPress的订阅到Feedburner
#Redirect wordpress content feeds to feedburner
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourfeed [R=302,NC,L]
</ifmodule>
20、禁止空Referrer访问内容
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
21、从URL中删除文件扩展名
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
22、将www.domain.com重定向到domain.com
#remove www from URI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
23、URL结尾添加/
#trailing slash enforcement
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !#
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301
24、将www.domain.com/xxx重定向到domain.com/xxx
# Redirect if www.yourdomain.com to yourdomain.com
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
Apr
21
# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}
rewrite “^/(.*)-p-(.*).html$” /index.php?main_page=product_info&products_id=$2&% last;
rewrite “^/(.*)-c-(.*).html$” /index.php?main_page=index&cPath=$2&% last;
rewrite “^/(.*)-m-([0-9]+).html$” /index\.php?main_page=index&manufacturers_id=$2&% last;
rewrite “^/(.*)-pi-([0-9]+).html$” /index\.php?main_page=popup_image&pID=$2&% last;
rewrite “^/(.*)-pr-([0-9]+).html$” /index\.php?main_page=product_reviews&products_id=$2&% last;
rewrite “^/(.*)-pri-([0-9]+).html$” /index\.php?main_page=product_reviews_info&products_id=$2&% last;
# For wordpress on zencart by Jeff
rewrite “^/wp/(.*).html$” /index.php?main_page=wordpress&page_id=$1&% last;
# For eazy pages
rewrite “^/(.*)-ezp-([0-9]+).html$” /index\.php?main_page=page&id=$2&% last;
# For Open Operations Info Manager
rewrite “^(.*)-i-([0-9]+).html” /index.php?main_page=info_manager&pages_id=$2&% last;
# For dreamscape¡¯s News & Articles Manager
rewrite “^news/?” /index.php?main_page=news&% last;
rewrite “^news/rss.xml” /index.php?main_page=news_rss&% last;
rewrite “^news/archive/?” /index.php?main_page=news_archive&% last;
rewrite “^news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html” /index.php?main_page=news&date=$1-$2-$3&% last;
rewrite “^news/archive/([0-9]{4})-([0-9]{2}).html” /index.php?main_page=news_archive&date=$1-$2&% last;
rewrite “^news/(.*)-a-([0-9]+)-comments.html” /index.php?main_page=news_comments&article_id=$2&% last;
rewrite “^news/(.*)-a-([0-9]+).html” /index.php?main_page=news_article&article_id=$2&% last;
# All other pages
# Don‘t rewrite real files or directories
rewrite “^(.*).html” /index.php?main_page=$1&% last;
if (-f $request_filename) {
break;
}
rewrite “^/(.*)-p-(.*).html$” /index.php?main_page=product_info&products_id=$2&% last;
rewrite “^/(.*)-c-(.*).html$” /index.php?main_page=index&cPath=$2&% last;
rewrite “^/(.*)-m-([0-9]+).html$” /index\.php?main_page=index&manufacturers_id=$2&% last;
rewrite “^/(.*)-pi-([0-9]+).html$” /index\.php?main_page=popup_image&pID=$2&% last;
rewrite “^/(.*)-pr-([0-9]+).html$” /index\.php?main_page=product_reviews&products_id=$2&% last;
rewrite “^/(.*)-pri-([0-9]+).html$” /index\.php?main_page=product_reviews_info&products_id=$2&% last;
# For wordpress on zencart by Jeff
rewrite “^/wp/(.*).html$” /index.php?main_page=wordpress&page_id=$1&% last;
# For eazy pages
rewrite “^/(.*)-ezp-([0-9]+).html$” /index\.php?main_page=page&id=$2&% last;
# For Open Operations Info Manager
rewrite “^(.*)-i-([0-9]+).html” /index.php?main_page=info_manager&pages_id=$2&% last;
# For dreamscape¡¯s News & Articles Manager
rewrite “^news/?” /index.php?main_page=news&% last;
rewrite “^news/rss.xml” /index.php?main_page=news_rss&% last;
rewrite “^news/archive/?” /index.php?main_page=news_archive&% last;
rewrite “^news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html” /index.php?main_page=news&date=$1-$2-$3&% last;
rewrite “^news/archive/([0-9]{4})-([0-9]{2}).html” /index.php?main_page=news_archive&date=$1-$2&% last;
rewrite “^news/(.*)-a-([0-9]+)-comments.html” /index.php?main_page=news_comments&article_id=$2&% last;
rewrite “^news/(.*)-a-([0-9]+).html” /index.php?main_page=news_article&article_id=$2&% last;
# All other pages
# Don‘t rewrite real files or directories
rewrite “^(.*).html” /index.php?main_page=$1&% last;
Nov
30
把以下代码复制到网站目录中的配置文件web.config中的 <system.webServer>之后就可以了。
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^archiver/((fid|tid)-[\w\-]+\.html)$" ignoreCase="false" />
<action type="Rewrite" url="archiver/index.php?{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 2">
<match url="^forum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="forumdisplay.php?fid={R:1}&page={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 3">
<match url="^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="viewthread.php?tid={R:1}&extra=page\%3D{R:3}&page={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 4">
<match url="^space-(username|uid)-(.+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="space.php?{R:1}={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 5">
<match url="^tag-(.+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="tag.php?name={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^archiver/((fid|tid)-[\w\-]+\.html)$" ignoreCase="false" />
<action type="Rewrite" url="archiver/index.php?{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 2">
<match url="^forum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="forumdisplay.php?fid={R:1}&page={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 3">
<match url="^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="viewthread.php?tid={R:1}&extra=page\%3D{R:3}&page={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 4">
<match url="^space-(username|uid)-(.+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="space.php?{R:1}={R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule 5">
<match url="^tag-(.+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="tag.php?name={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>