Question

I'd like to redirect everything in /bar/ to a new subdomain but still pass in any query parametes from the original URL. E.g

Original URL examples:

  1. http://www.foo.com/bar/
  2. http://www.foo.com/bar/index.php
  3. http://www.foo.com/bar/index.html
  4. http://www.foo.com/bar/test.php?id=123&utm_source=google

Should redirect to:

  1. http://bar.foo.com/
  2. http://bar.foo.com/
  3. http://bar.foo.com/
  4. http://bar.foo.com/?id=123&utm_source=google

This is what I currently have:

RewriteEngine On
RewriteRule ^bar/?(.*)$ https://bar.foo.com/? [R=301,L]

However, it doesn't pass in the query parameters I need in the 4th example above. I know the ? prevents query parameters being passed in so this will most likely need to be removed I assume but not sure what to replace it with?

Cheers

Était-ce utile?

La solution

Add a new rule like this:

RewriteEngine On

RewriteRule ^bar(/|$) https://bar.foo.com/ [NC,R=301,L]

QUERY_STRING will automatically be carried over to target URI.

Make sure there is no trailing ? in the target URI which strips existing query string.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top