【问题标题】:Mass 301 Moved Permanently redirectMass 301 Moved 永久重定向
【发布时间】:2015-08-11 19:23:59
【问题描述】:

我无法找到将 25 多个页面重定向到新 URL 的最佳方法。我已将一个 weebly 网站更新为 PHP 网站,因此所有 .html 链接现在都是 .php 并且一些文件已完全重命名(由于旧网站不支持移动设备而进行更新)。

我已经尝试了一些 .htaccess 的东西来将 .html 扩展更改为 .php ,但它似乎不适用于我的共享主机。

我可以使用php 301 redirect 并将其包含在404 page 中吗?还是会伤害SEO?有一个 404 到 301 到新页面?还有其他方法吗?除了使用旧名称创建 HTML 页面并添加元刷新之外?还是使用.htaccess

我查看了很多 over stacks,但它们不是 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

【问题讨论】:

  • 首先,请向我们展示您对.htaccess 的尝试。此外,对需要重定向的内容进行细分也会有所帮助。
  • 为了获得更好的帮助,发布您当前有问题的 .htaccess。
  • @anubhava @Mike Rockett 我添加了一些我尝试过的东西。请注意,我已经自己尝试了其中的每一个,并且只有 ErrorDocument 404 http://www.sitename.co.nz/404_error.php 有效。

标签: php html .htaccess http-status-code-301


【解决方案1】:

需要进行几项重要更改:

  1. 不要将mod_alias 规则与mod_rewrite 规则混用。
  2. 在内部重写之前保留重定向规则。

在 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]

清除浏览器缓存后进行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 2013-07-17
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    相关资源
    最近更新 更多