简体   繁体   English

质量301移动永久重定向

[英]Mass 301 Moved Permanently redirect

I am having trouble finding the best way to redirect 25+ pages to their new URLs. 我无法找到将25个以上页面重定向到其新URL的最佳方法。 I have updated a weebly site to a PHP one so all the .html links are now .php and some files are renamed completely (updating since the old site wasn't mobile responsive). 我已经将一个脆弱的网站更新为一个PHP网站,因此所有.html链接现在都为.php,并且某些文件已完全重命名(由于旧网站没有移动响应,因此正在更新)。

I have try some .htaccess things to change .html extensions to .php ones but it doesn't seem to work on my shared host. 我已经尝试了一些.htaccess东西来将.html扩展名更改为.php ,但是在我的共享主机上似乎不起作用。

Is there a php 301 redirect I can use and include on the 404 page ? 我可以使用php 301 redirect并将其包含在404 page吗? or will the hurt SEO? 还是会伤害SEO? Having a 404 to 301 to new page? 拥有404到301的新页面? Is there another way? 还有另一种方法吗? Other than creating HTML page with the old names and adding meta refresh? 除了使用旧名称创建HTML页面并添加元刷新之外? or using .htaccess ? 或使用.htaccess吗?

I have looked at a lot of over stacks but their not SEO focus or don't match my pro, I really want to keep SEO in mind. 我看过很多过多的文章,但他们不是SEO重点,还是与我的专业人士不符,我真的想牢记SEO。

ErrorDocument 404 http://www.sitename.co.nz/404_error.php

RewriteEngine On
RewriteCond %{REQUEST_URI} .html$
RewriteRule ^(.*).html$ /$1.php [R=301,L]

#http://www.inmotionhosting.com/support/website/redirects/setting-up-a-301-permanent-redirect-via-htaccess

Redirect 301 /oldfilea.htm /newfilea.htm
Redirect 301 /oldfileb.htm /newfileb.htm
Redirect 301 /oldfilec.htm /newfilec.htm
Redirect 301 /oldfilee.htm /newfilee.htm
Redirect 301 /oldfiled.htm /newfiled.htm

Couple of important changes needed: 需要进行几个重要的更改:

  1. Don't mix mod_alias rules with mod_rewrite rules. 不要将mod_alias规则与mod_rewrite规则混合使用。
  2. Keep redirect rules before internal rewrite ones. 在内部重写规则之前保留重定向规则。

Try this in root .htaccess: 在root .htaccess中尝试以下操作:

ErrorDocument 404 http://www.sitename.co.nz/404_error.php

RewriteEngine On

RewriteRule ^oldfilea\.htm$ /newfilea.htm [L,NC,R=301]
RewriteRule ^oldfileb\.htm$ /newfileb.htm [L,NC,R=301]
RewriteRule ^oldfilec\.htm$ /newfilec.htm [L,NC,R=301]
RewriteRule ^oldfilee\.htm$ /newfilee.htm [L,NC,R=301]
RewriteRule ^oldfiled\.htm$ /newfiled.htm [L,NC,R=301]

RewriteRule ^(.+?)\.html$ /$1.php [R=301,L,NC]

Test this after clearing your browser cache. 清除浏览器缓存后进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM