利用.htaccess文件实现301重定向跳转的代码原理

2019-04-21 11:41 阅读 2,325 views 次 评论 0 条

(谭云财SEO顾问)我们偶尔在网站搭建完成之后,可能域名当中的一些页面和代码是需要修改,也就是很多页面可能卡顿的现象,可能上午收录了下午就打不开网站了这个时候似乎很多人不知道该怎么解决,这个时候就需要做好301跳转, seo技术博客带你瞧瞧网站在优化当中利用.htaccess文件做301重定向的代码实现。

举个简单的例子,如果用http://www.tanyuncai.com/seotech/415.html跳转到http://tanyuncai.com/seotech/415.html的话,该怎么处理和设置呢?在.htaccess文件当中这样编辑:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.tanyuncai.com$
RewriteRule ^seotech/415.html$  http://tanyuncai.com/seotech/415.html[R=301,L]

如果你有N多个内页需要做301怎么办呢?如下

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.tanyuncai.com$
RewriteRule ^seotech/415.html$ http://tanyuncai.com/seotech/415.html [R=301,L]
RewriteRule ^product/gyz/$ http://tanyuncai.com/seotech/product/gyz/ [R=301,L]

如果说上面这种方法不行(可以跳转但是不会返回404状态码),那么你还有写嘛这种写法可选择,同样是写到.htaccess里面的。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.tanyuncai.com$
RewriteRule ^seotech/399.html$  http://tanyuncai.com/seotech/399.html[R=301,L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.tanyuncai.com$
RewriteRule ^seotech/352.html$ http://tanyuncai.com/seotech/352.html [R=301,L]

所以在网站当中需要给内页做301重定向代码跳转的时候,我们只需要编辑好这个.htaccess文件就是可以轻松实现的了。(武汉seo优化)

 

 

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:利用.htaccess文件实现301重定向跳转的代码原理 | 谭云财SEO顾问自媒体博客

发表评论


表情