Forum

Rewrite, but for domain?

James
26 November 2017, 22:06
I want to 301 all requests to example.com/~user7/<path> to user7.example.com/<path> (only for a specific user)

I see that the UrlToolkit is used for this, however, the Redirect directive seems to not allow customizing the URL at all, and the Rewrite directive seems to not allow customizing the domain at all.

What do I need to enter into the configfile to redirect all requests as such?
James
26 November 2017, 22:27
The following nearly works, but ends up just sending to www.example.com/~user7/user7.example.com/user7.example.com/user7.example.com/user7.example.com/..until after 7 redirects it 414s

UrlToolkit {
ToolkitID = user7
Match ^/~user7/?(.*) Redirect 301 //user7.example.com/$1
}
James
26 November 2017, 22:48
I seem to have solved it. (Although, imperfectly and a suggestion would be handy as to auto-protocol selection)

For the future reference / anyone on Google:
while
UrlToolkit {
ToolkitID = user7
Match ^/~user7/?(.*) Redirect //user7.example.com/$1
}

and like variations don't work at all, creating a an exponentially growing URL culminating in a 414 error,

the following:
UrlToolkit {
ToolkitID = user7
Match ^/~user7/?(.*) Redirect http://user7.example.com/$1
}

DOES WORK (although you must manually code in the HTTP/HTTPS; there is no allowing to select automatically based on the previous request

For instance, the latter rule above leads to the following:

curl -sLvo/dev/null http://www.example.com/~user7/lmao123
* Trying 2001:db8:1337::1...
* TCP_NODELAY set
* Connected to www.example.com (2001:db8:1337::1) port 80 (#0)
> GET /~user7/lmao123 HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sun, 26 Nov 2017 21:40:09 GMT
< Server: Hiawatha v10.7
< Accept-Ranges: bytes
< Connection: keep-alive
< Location: http://user7.example.com/lmao123
< Content-Length: 798
< Content-Type: text/html
<
* Ignoring the response-body
{ [798 bytes data]
* Curl_http_done: called premature == 0
* Connection #0 to host www.example.com left intact
* Issue another request to this URL: 'http://user7.example.com/lmao123'
* Trying 2001:db8:1337::2...
* TCP_NODELAY set
* Connected to user7.example.com (2001:db8:1337::2) port 80 (#1)
> GET /lmao123 HTTP/1.1
> Host: user7.example.com
> User-Agent: curl/7.52.1
> Accept: */*
>
Hugo Leisink
27 November 2017, 12:53
You could try redirecting to ://<hostname> instead of http:// or https://. If I remember correctly, a browser then uses the current scheme. I have no time testing it myself at the moment.
This topic has been closed.