12种实现301网页重定向方法的代码实例(含Web编程
为什么需要使用301重定向:
1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不会影响到搜索引擎对页面的排名。
2. 保留访客和流量: 如果你将页面链接到大量方法可以访问过的地址,如果不是用重定向的话你就会失去这些用户(不解)原文If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.
狼蚁网站SEO优化是 11 中实现 301 重定向的方法
1. HTML 重定向/Meta 刷新
将狼蚁网站SEO优化 HTML 重定向代码放在网页的 <head> 节点内
<meta HTTP-EQUIV="REFRESH" content="0; url=http://.yourdomain.">
上述代码立即将访客重定向到一个页面,你可以修改 content 中 的 0 这个值来表示几秒钟后才进行重定向。例如 content="3; url=http://.oschina./" 表示三秒后再重定向。
2. PHP 重定向
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://.new-url." );
?>
3. ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://.new-url./"
%>
4. ASP .NET Redirect
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://.new-url.");
}
</script>
5. JSP Redirect
<%
response.setStatus(301);
response.setHeader( "Location", "http://.new-url./" );
response.setHeader( "Connection", "close" );
%>
6. CGI PERL Redirect
$q = new CGI;
print $q->redirect("http://.new-url./");
7. Ruby on Rails Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://.new-url./"
end
8. ColdFusion Redirect
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://.new-url.">
9. Javascript URL Redirect
<head>
<script type="text/javascript">
window.location.href='http://.newdomain./';
</script>
</head>
10. IIS Redirect
在 Inter 服务管理器中右击你想要重定向的文件和文件夹,选择 "a redirection to a URL".
然后输入目标网址,选中 "The exact url entered above" 和 "A permanent redirection for this resource" 然后点击 'Apply' 按钮。
11. 使用 .htaess 进行重定向
创建一个 .htaess 文件(代码如下)用来将访问呢 domain. 重定向到 .domain. 下,该文件必须放置在网站的root目录,也就是首页放置的目录。
RewriteEngine on
rewritecond %{http_host} ^domain. [nc]
rewriterule ^(.)$ http://.domain./$1 [r=301,nc]
注意: .htaess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模块启用的情况下使用。
12.Nginx中的rewrite
server {
server_name .jb51. jb51.;
if ($host = 'jb51.' ) {
rewrite ^/(.)$ https://.jb51./$1 permanent;
}
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指