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

Redirect root domain to path

· 52CE 我爱测

Searched all questions by redirect keyword (e.g. 1 , 2 ) but none of them fit my case. I want to redirect my domain ( www.example.com ) to another (sub-)domain including path and query if possible: www.lokki.newdomain.com/resourc…

问题原文

原帖链接 · Suncatcher · CC BY-SA 4.0

Searched all questions by redirect keyword (e.g. 1, 2) but none of them fit my case.

I want to redirect my domain (www.example.com) to another (sub-)domain including path and query if possible:

www.lokki.newdomain.com/resources/index.html?crsource=google&category=web

I do not host second domain website and since that I have no access to its configuration.

My registrar allows setting up domain forwarding but only mirroring one:

example.com/resources/index.html -> newdomain.com/resources/index.html

and I want to set up redirect from my root directly to document.

Is there a way?

UPDATE: having in place AWS instance, what would be the most effortless way of implementing such redirect?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

You can use a DNS A record to point the domain to the IP address of your Linux instance. Assuming that the instance is running Apache, you would then create a virtual host that does this redirect:

<VirtualHost *:*>
    ServerName example.com
    RedirectMatch ".*" "https://www.lokki.newdomain.example/resources/index.html?crsource=google&category=web"
</VirtualHost>

You don't say what Linux distribution you are running, so where this configuration needs to go can be a bit different. On Debian based distributions such as Ubuntu or Mint it would go in /etc/apache2/sites-available/example.com.conf then you would use the commands sudo a2ensite example.com and sudo service apache2 reload to enable it and load the configuration into the already running server instance.

Using Nginx, the syntax would be the following, but I'm not sure which file it would go in.

server {
  server_name .example.com;
  return 301 https://www.lokki.newdomain.example/resources/index.html?crsource=google&category=web;
}

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

资料来源与适用范围

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

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

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