문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top