我有一个小困境。
我已经从事一个项目近一年了,并且拥有一个旧域名。不知道谷歌如何在旧域名下索引整个网站,这让我很担心。我想将该网站放在我的新域名上,并且我认为执行 301 是前进的方向。我需要在每个动态页面上执行此操作。好处是页面结构是相同的。
任何有关最佳方法的建议将不胜感激。
I have a small dilemma.
I have been working on a project for almost a year now and had an old domain name. Not knowing how Google has indexed the whole site under the old domain which has worried me. I want to put the site up on my new domain name and I think doing a 301 is the way forward. I will need to do this on every dynamic page. The good thing is the page structure is identical.
Any advice on the best way to do this would be massively appreciated.
发布评论
评论(4)
最好的方法是创建一个
.htaccess
文件(如果您还没有)并将其粘贴到您的 html 文件夹中。The best way is to create a
.htaccess
file if you don't have one already and stick it in your html folder.这会将所有内容从 olddomain.com 重定向到 newdomain.com:
您可以将该 mod_rewrite 代码放入 olddomain 的 .htaccess 中。
This will redirect everything from olddomain.com to newdomain.com:
You can put that mod_rewrite code into your olddomain's .htaccess.
如果您的托管地点不支持 mod_rewrite (是的,有这样的托管公司)或者它由于某些奇怪和未知的原因而不起作用,请使用更简单且广泛使用的指令: 重定向 或 重定向匹配。
将这样的行放入旧域的
.htaccess
中:上面的行将使用 301 代码(永久重定向)将所有 URL 从旧域重定向到新域,从 SEO 角度来看,这是正确的。
如果您需要重定向这样的单个页面或将其指向特定的新位置,请使用这样的规则(与上面相同,只是指定确切的 URL):
Apache mod_rewrite 手册有一个页面: 何时不使用 mod_rewrite。那里列出了这个特定的场景(就资源而言,Redirect 比 RewriteRule 轻得多,这在非常繁忙的服务器上可能是一个问题)。
If your hosting place does not support mod_rewrite (yep, there are such hosting companies) or it does not work for some strange and unknown reason, go with a simpler and widely available directive: Redirect or RedirectMatch.
Put such line into your
.htaccess
on old domain:The above line will redirect ALL URLss from old domain into new domain suing 301 code (Permanent Redirect) which is the right thing from SEO perspective.
If you need to redirect such a single page or point it to a specific new location, use such rule (the same as above just specifying exact URL):
Apache mod_rewrite manual has a page: When NOT to use mod_rewrite. This particular scenario is listed there (Redirect is much lighter that RewriteRule in terms of resources, which can be an issue on very busy servers).
有一种方法可以通过 php 来做到这一点(.htaccess 是最好的),但这对我来说已经派上用场了一两次。
There is a way to do it via php (.htaccess is the best), but this has come in handy for me once or twice.