nginx 和apache 过滤蜘蛛跳转

apache

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !^.*Baiduspider [NC]
RewriteCond %{HTTP_HOST} ^cms.c.com [NC]
RewriteRule ^(.*)$ http://www.baidu.com [R=301,L]

 nginx

server {
        listen       80;
        server_name  cms.c.com;
        
        set $flag 0;
        if ($http_user_agent ~* "Baiduspider|googlebot|bing|sogou|yahoo"){
                set $flag "1";
        }

        if ($flag != "1") { 
                rewrite ^/(.*)$ http://www.baidu.com permanent; 
        }               
        
        root   "E:/php-Project/cms.c.com";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

  

猜你喜欢

转载自www.cnblogs.com/saonian/p/10837317.html