301重定向代码(ASP,ASP.NET,PHP,apache,IIS,ISAPI_Rewrite)
分类:程序开发 Tags: asp php apache iis rewrite 评论:1 浏览:5661 最近更新时间:2020/12/23 15:45:05
一般跳转有三种,通过asp或php程序,页面中meta和js跳转。
其中,meta和js跳转都属于302跳转,301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。
以下是一些我整理的代码:
asp:
<% Response.Status="301 Moved Permanently" Response.AddHeader "Location","http://www.yuzhiguo.com" %>
php:
<? Header( "HTTP/1.1 301 Moved Permanently" ) ; Header( "Location: http://www.yuzhiguo.com" ); ?>
asp.net
<script runat="server"> private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader ("Location","http://www.yuzhiguo.com"); } </script>
apache下设置httpd.conf或者站点的.htaccess
Redirect permanent / http://www.yuzhiguo.com/ (将目录下所有内容重定向到http://www.yuzhiguo.com/相应的内容)
Redirect permanent / http://www.***.com/links.php (将网站首页重定向到指定文件:http://www.***.com/links.php)
注意有permanent,没有的话也能重定向,但属于302重定向。
IIS下
1,打开internet信息服务管理器,在欲重定向的网页或目录上按右键
2,选择“重定向到URL”
3,在“重定向到”输入框中输入要跳转到的目标网页的URL地址
4,选中“资源的永久重定向”(切记)
5,最后点击“应用”
使用ISAPI_Rewrite来实现:
(2.X版本文件为httpd.ini,3.X版本文件为.htaccess,文件放在网站根目录生效)
1. 将不带www的顶级域名301重定向到带www的域名
# ISAPI_Rewrite 2.x 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteCond Host: ^yuzhiguo\.com$ RewriteRule (.*) http\://www\.yuzhiguo\.com$1 [I,RP]
# ISAPI_Rewrite 3.0 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteCond %{HTTP:Host} ^yuzhiguo\.com$ RewriteRule (.*) http\://www\.yuzhiguo\.com$1 [NC,R=301]
2. 不同域名之间的301转向
# ISAPI_Rewrite 2.x 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteCond %{HTTP:Host} ^yuzhiguo\.cn$ RewriteRule (.*) http\://www\.yuzhiguo\.com$1 [NC,R=301]
# ISAPI_Rewrite 3.0 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteCond %{HTTP:Host} ^www\.yuzhiguo\.cn$ RewriteRule (.*) http\://www\.yuzhiguo\.com$1 [NC,R=301]
3. 将页面301重定向到另外一个页面
# ISAPI_Rewrite 2.x 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html$ http://yuzhiguo.com/dll.html[I,O,RP,L]
# ISAPI_Rewrite 3.0 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html$ http://yuzhiguo.com/dll.html[NC,L,R=301,O]
opencart 301跳转
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yuming.com$ [NC]
RewriteRule ^(.*)$ http://www.yuming.com/$1 [R=301,L]
</IfModule>
-
• asp中判断一个字符是不是汉字
• 一个空间/虚拟主机放置多个网站的转向代码(多个域名绑定一个空间)
• 解决IE6下float浮动margin出现双倍距离问题
• ASP检测网站是否能打开代码
• ASP判断身份证号码输入是否正确函数代码
• ASP保存远程图片文件到本地代码
• ASP按字段中首字母输出所有数据代码
• opencart 3.0 PayPal Payments Standard支付没有传递收货地址解决办法
• 去除新版宝塔面板首页的强制手机登录窗口教程
• 支付宝即时到账POST按钮代码
-
• 如何有效防止网站出现垃圾留言,垃圾评论?
• Windows Media Player 11绕过XP正版验证的方法
• FireFox火狐浏览器有用的设置方法记录
• 通用ASP生成HTML代码,无需读取模版
• 263企业邮箱添加子用户教程
• 如何免费点亮、关闭熄灭QQ音速图标?
• 如今外贸网站支持https访问很有必要,提升客户信任度
• 如何免费点亮、关闭熄灭QQ音信图标?
• zoho开启多因素验证后无法登录foxmail,需要生成专用密码来登录
• 教你如何使用电脑键盘上的Shift键
-
• Google Workspace gmail企业邮箱老板监控员工邮件操作方法
• zoho企业邮箱开启手机验证码双重认证教程
• 外贸网站如何使用Google Search Console谷歌管理员工具
• 腾讯企业邮箱开启安全登录后,如何登录foxmail收发信
• 获取小红书无水印图片的原理
• iis如何支持.webp图片格式访问
• FireFox火狐浏览器有用的设置方法记录
• 最新政策 Google免费版企业邮箱个人用途可以继续保留免费版
• MySQL报Field‘***’doesn’t have a default value错误的解决办法
• 抖音国际版TikTok注册过程记录