0

I recently switched to a new domain for a version control server I run. The server is usually accessed with a username included in the url such as https://[email protected]/some/stuff. I want to redirect requests to the old domain to the new domain and preserve everything else in the url (including the username). So the former url would be redirected to https://[email protected]/some/stuff. Currently I have the following rewrite condition and rule:

RewriteCond %{HTTP_HOST} sub\.olddomain\.com 
RewriteRule (.*) https://sub.newdomain.net$1 [R=301,L]

This works except it drops the userinfo part of the URL. Is there a way I can preserve the user info?

1
  • You might try some condition using %{REMOTE_USER} Oct 28, 2013 at 22:28

1 Answer 1

2

From the perspective of the server user info isn't part of the URL. When you request a URL with a user name your browser will set an authorization header. The user name is available to rewriterules however, in the %{REMOTE_USER} variable.

So you could try something like:

RewriteCond %{HTTP_HOST} sub\.olddomain\.com 
RewriteRule (.*) https://%{REMOTE_USER}@sub.newdomain.net$1 [R=301,L]

The user will have to authenticate again on the new server however. There's no way around that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .