问题
I have over 50 html pages that I'm going to move to different folders in the same domain.
How to properly make 301 redirects for each one?
Some people said to place the redirect in meta
html tags. Like this <meta http-equiv="refresh" content="0; url=http://example.com/" />
Some other people are saying to make it inside the .htaccess file, I'm not sure what's the best way?
My goal is to redirect the old URLs to the URLs without losing the page rank in Google.
回答1:
In most instances, a 301 redirect is the best way to implement redirects on a website. Using a meta refresh won't let the reading entity (Google, a browser or otherwise) know that it's permanent and thus would have a negative impact in terms of SEO.
A 301 redirect essentially means "Moved Permanently" as an HTTP status code and will be recognised for SEO purposes.
Achieving this within an .htaccess file is the most efficient way of doing this as it's all done in one place and won't require the potential editing of all the individual files (50 in your case).
Do this as a simple list inside an .htaccess file:
RewriteEngine on
Redirect 301 /oldfolder/file1.html /newfolder/file1.html
Redirect 301 /oldfolder/file2.html /newfolder/file2.html
Or, if all the files reside in one folder, you could use a ReWriteRule similar to below that's a lot quicker to test and implement:
RewriteEngine on
RewriteRule ^oldfolder/(.*)$ /newfolder/$1 [R=301,NC,L]
For reference:
R=301 tells search engines that the redirection is permanent
NC tells the engine not to care about the characters in the rule
L tells Apache it's the last rule and will avoid parsing/loops etc
回答2:
Meta Refresh Redirects are not the same as 301 redirects. And I also advise you to not use this, it can even affect your Google ranking negatively. Please use .htaccess
For more information about redirection, please read this
回答3:
If you want exact match:
redirectMatch 301 /old /new
回答4:
Redirect 301 /pagename.php http://www.testdomain.com/pagename.html
Notice: old path in add only page name and a new path in add with domain name
来源:https://stackoverflow.com/questions/48886601/how-to-properly-make-301-redirect