3

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?

  • Redirecting requires a web server. It isn't possible to redirect without having some minimal amount of hosting. In other words, it isn't possible to redirect with just DNS. – Stephen Ostermiller Nov 5 at 14:22
  • Ok, and such service as Cloudflare that was mentioned? It can be useful? – Suncatcher Nov 5 at 20:47
  • I also have AWS Linux instance, how to set up such redirection with minimum effort? Could you point out some documentation? Updated the question and removed no-hosting requirement – Suncatcher Nov 5 at 20:48
  • You referred to both www.example.com and example.com in your question - note that these are different hostnames and consequently both will need to be configured in your AWS instance if you wish to redirect from both. – MrWhite Nov 6 at 0:07
  • Use redirect.center – DavChana Nov 8 at 5:44
2

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;
}
  • I'm running AMI Linux, Amazon's fork of CentOS. Can nginx also be an option? – Suncatcher Nov 5 at 21:08
  • Sure, Nginx can do it. I edited some config into my answer. – Stephen Ostermiller Nov 5 at 21:14
  • Thanks, will try – Suncatcher Nov 5 at 21:22
  • Thanks, I've successfully configured redirection, it works. Can you please suggest how to do so that original URL is showed in address bar (www.example.com), not target long URL? Tried proxy_pass and rewrite but that didn't work – Suncatcher Nov 24 at 3:08
  • You would have to use proxy_pass across host names. However, I don't know nginx well enough to answer that. You should probably ask another question here about it. Specifically, I don't know how you would proxy all wildcard URIs to a specific page on the other server. – Stephen Ostermiller Nov 24 at 10:48
-2

Cloudflare Webworkers or Nginx reverse proxy redirection could be worth a shot.

  • 2
    Such a short answer is not high quality. Can you explain how to use those? It would also be helpful to link to documentation for them. – Stephen Ostermiller Nov 5 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.