大网数据广告活动
网站运营与故障问答

Redirecting 404 pages to another active pages in .htaccess

· 52CE 我爱测

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 o…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。