Nick Mudgett
Nick Mudgett

Reputation: 57

Redirect domains on htaccess

I have been doing research for hours on stack overflow but can't seem to find anything that works for me. I am not sure if its my server setup or what but here is what I am faced with.

I have a live version of a web app and a beta test version as well. The folder structures are exactly the same. I want the data to be consistent for both the live and beta versions. I use the same MySQL tables for this. There is 1 folder with images that I want to redirect someone using my beta version to the live version. For example:

If someone types in https://beta.example.com/images/ImageName I want them to be redirected to https://live.example.com/images/ImageName

I assume the best way to do this is using .htaccess, but I am open to suggestions.

Any help is much appreciated.

Upvotes: 0

Views: 29

Answers (1)

Wafflecode
Wafflecode

Reputation: 55

Using Apache, this can easily be done with it's .htaccess file as you suggest.

However your question tagged nginx. As a more performance oriented server nginx likes to avoid per-directory config files like Apache's .htaccess. Are you using Apache or nginx?

Here is one basic way in Apache:

  1. Configure both beta / live sites as normal.
  2. In the beta site's config (or .htaccess), use a RewriteRule matching the rewrite this to the live version. Or the reverse. See the examples from the official docs. In particular: From Old to New - Internal and the substitution examples.

Here is an untested example:

RewriteEngine  on
RewriteRule    "^images(.*)" "https://live.example.com/images$1"

See this page for the way nginx would do it.

Did I understand your question correctly?

Upvotes: 1

Related Questions