1

I'm a little stuck. I have the following redirect in .htaccess

Redirect http://www.domain1.com http://www.domain2.com/subdomain=

Although I want that if someone types www.domain1.com/12345, it will automatically append the 12345 to the redirect URL on redirect so it will go to www.domain2.com/subdomain=12345.

i.e. whatever they append to the original, will be appended to the new redirect (without a / before it).

Obie
  • 13
  • 2

1 Answers1

0

You should use RedirectMatch instead of Redirect. See manual

Resource Moved to Another Server

#With RedirectMatch RedirectMatch "^/docs/(.*)" "http://new.example.com/docs/$1"

In your case:

RedirectMatch ^/(.*)$ http://www.domain2.com/subdomain=$2
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
  • Thanks! Just tried this, but it seems to redirect to the homepage instead i.e. just www.domain2.com, any thoughts? – Obie Mar 29 '16 at 21:40
  • `it seems to redirect to the homepage instead`. Can you explain this phrase. I understood: you go to `www.domain1.com/12345` and it redirects to `www.domain2.com` instead of `http://www.domain2.com/subdomain=$2`. Is this your current problem with suggested solution? Or I misunderstood you? – alexander.polomodov Mar 29 '16 at 21:45
  • Managed to fix it! There was an & symbol in the redirect link which for some reason automatically got replaced?! Therefore, the site cannot find the page and redirects to homepage. I added a backslash before the & sign and it worked.. I may not have explained it properly, but it was basically this issue: http://stackoverflow.com/questions/10905048/htaccess-redirect-replacing-sign-with-the-search - Thanks though @alexander.polomodov, much appreciated! – Obie Mar 29 '16 at 22:49