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

301 redirect with Apache: All paths of URL to a single path

· 52CE 我爱测

I am migrating a website from one platform to another, and in that process, I'm getting rid of the old domain name. There is no direct relation between the path s on the old and new website, and therefore, I want to redirect all …

问题原文

原帖链接 · Kristian · CC BY-SA 3.0

I am migrating a website from one platform to another, and in that process, I'm getting rid of the old domain name. There is no direct relation between the paths on the old and new website, and therefore, I want to redirect all old paths to the new websites' front page: I.e. olddomain.example/any_path should redirect to the front page of newdomain.example. I am aware of the SEO consequences of this.

My current solution is to use the RedirectPermanent directive, so that my .htaccess in the domain's root directory contains:

RedirectPermanent / https://newdomain.example/

How do I achieve that any path on olddomain.example (e.g. olddomain.example/any_path) is redirected to the front page (and not the corresponding path) of newdomain.example?

已采纳解答

原帖链接 · Matthew Edgar · CC BY-SA 3.0

I think this should do the trick for you. On the old domain, put this code in the .htaccess file (this assumes a 301 redirect is used).

RewriteEngine On
RewriteRule (.*) https://newdomain.example [R=301,L]

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

资料来源与适用范围

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

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

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