Apache相關操作

配置域名跳轉
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^www.domain1.com$
        RewriteRule ^/(.*)$ http://www.domain2.com/$1 [R=301,L]
    </IfModule>
如果是多個域名,可以這樣設置:
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^www.domain.com [OR]
        RewriteCond %{HTTP_HOST} ^www.domain1.com$
        RewriteRule ^/(.*)$ http://www.domain2.com/$1 [R=301,L]
    </IfModule>
或者:    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^www.domain2.com$
        RewriteRule ^/(.*)$ http://www.domain2.com/$1 [R=301,L]
    </IfModule>

配置apache的訪問日誌

ErrorLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-error_%Y%m%d.log 86400"
    SetEnvIf Request_URI ".*\.gif$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.jpg$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.png$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.swf$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.js$" p_w_picpath-request
    SetEnvIf Request_URI ".*\.css$" p_w_picpath-request
    CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-access_%Y%m%d.log 86400" combined env=!p_w_picpath-request

配置靜態文件緩存
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType p_w_picpath/gif  "access plus 1 days"
    ExpiresByType p_w_picpath/jpeg "access plus 24 hours"
    ExpiresByType p_w_picpath/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"    
    ExpiresByType application/javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>
或者使用mod_headers模塊實現
<ifmodule mod_headers.c>  
# htm,html,txt類的文件緩存一個小時  
<filesmatch "\.(html|htm|txt)$">  
header set cache-control "max-age=3600"  
</filesmatch>  
# css, js, swf類的文件緩存一個星期  
<filesmatch "\.(css|js|swf)$">  
header set cache-control "max-age=604800"  
</filesmatch>  
# jpg,gif,jpeg,png,ico,flv,pdf等文件緩存一年  
<filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">  
header set cache-control "max-age=29030400"  
</filesmatch>  
</ifmodule>  

配置防盜鏈
SetEnvIfNoCase Referer "^http://.*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer ".*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)"> 
Order Allow,Deny 
Allow from env=local_ref 
</filesmatch> 

訪問控制
<Directory /data/www/>
            Order deny,allow
            Deny from all
            Allow from 127.0.0.1
</Directory>

針對請求的uri去限制
    <filesmatch "(.*)admin(.*)">
            Order deny,allow
            Deny from all
            Allow from 127.0.0.1
    </filesmatch>

某個某陸下禁止解析php
<Directory /data/www/path>
    php_admin_flag engine off             
    <filesmatch "(.*)php">
            Order deny,allow
            Deny from all
    </filesmatch> 
</Directory>

apache rewrite相關
apache 限制指定user_agent  http://www.lishiming.net/thread-1033-1-1.html
apache 限制某些目錄不能訪問通過rewrite實現  http://www.lishiming.net/thread-3587-1-1.html
apache rewrite 出現死循環  http://www.lishiming.net/thread-1043-1-1.html

discuz僞靜態配置:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/topic-(.+)\.html$ /portal.php?mod=topic&topic=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/article-([0-9]+)-([0-9]+)\.html$ /portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/group-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=group&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/blog-([0-9]+)-([0-9]+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/archiver/(fid|tid)-([0-9]+)\.html$ /archiver/index.php?action=$1&value=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ /plugin.php?id=$1:$2&%1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章