专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

shell脚本实现http 301代码重定向

百度收藏 QQ搜藏

原文:http://bash.cyberciti.biz/file-management/send-http-code-301-moved-permanently-redirection/

以下是该shell脚本的源代码:

#!/bin/bash
# Shell script to update old php files to point out to new CMS url
# it placed http code 301.
# You must create an array in following format:
# path/to/old/url1.php  path/to/new/url/slug/
# --------------------------------------------------------------------------
# Copyright (C) 2008 nixCraft project 
# This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- declare -a t=("http://domain.com/1.php" "http://domain.com/new/path/slug/" "http://domain.com/2.php" "http://domain.com/new/path/slug/" "http://domain.com/3.php" "http://domain.com/new/path/slug/" "http://domain.com/4.php" "http://domain.com/new/path/slug/" "http://domain.com/5.php" "http://domain.com/new/path/slug/") # set array total array size -1 ; if you have 5 item it should set to 4 for i in `seq 0 4` do #only work on zero or even element if [ $i -eq 0 -o $( expr $i % 2 ) -eq 0 ]; then s="${t[$i]}" d="${t[` expr $i + 1 ` ]}" file=$(basename $s) echo "Patching $file...." if [ -f $file ]; then # if file exists, create new php redirection code echo '<?php'>$file echo 'header("HTTP/1.1 301 Moved Permanently");'>>$file echo 'header("Location: ' $d '");'>>$file echo '?>'>>$file fi fi done
上一篇:shell脚本(功能:读取/etc/passwd文件计算输出用户数) 下一篇:shell脚本(功能:读取3个数字并找出里面最大的)

power by soyo123 2007-2008