问题原文
原帖链接 · paranoic · CC BY-SA 4.0
I have one product page indexed on Google but that link does not exist anymore and hits 404 page.
What I want to do is to redirect that link in .htaccess to another product page since it ranks very high. So I tryed almost every option and combination i.e.
Redirect 301 /old-page.html /new-page.html
Redirect 301 http://www.example.com/old-page.html http://www.example.com/new-page.html
etc. but none of those works for me.
Could anyone help me, is there any other solution or practice how to redirect thispage to another.
Btw. my links path contain 2 subfolders each like:
http://www.example.com/subfolder1/subfolder2/product.html
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
Without knowing the exact URL you are trying to redirect it's difficult to say whether you were experiencing a conflict with your existing directives or not. Although, if you were still seeing a 404 then your first directive:
Redirect 301 /old-page.html /new-page.html
...should have still "worked" (providing you are on Apache 2.2.6+)
However, since you already have a lot of existing mod_rewrite directives, you should really be using a mod_rewrite RewriteRule for this redirect, instead of a mod_alias Redirect. The reason being that mod_rewrite executes before mod_alias, regardless of the order of directives in .htaccess, so you can get unexpected conflicts (you already have many mod_rewrite redirects) or at the very least unnecessary additional processing before the redirect.
Try something like the following at the very top of your .htaccess file:
RewriteRule ^subfolder/old-page\.html$ https://www.example.com/subfolder/new-page.html [R=302,L]
Note there is no slash prefix on the RewriteRule pattern. I've included https and the full URL in the substitution since you do have a HTTP to HTTPS redirect later in the file.
I would add, however, that your directives do seem a bit muddled in that you have rewrites before redirects and your canonical non-www to www and HTTP to HTTPS redirects are at the very end so may get skipped entirely.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
