0

I am using the following directive in my .htaccess file:

RedirectMatch 301 ^/user/(.*)?$ http://$1.example.com/user/$1

to redirect the URL

example.com/user/koko/

but it redirects to http://koko/.example.com/user/koko instead of http://koko.example.com/user/koko.

How can I remove the extra slash from http://koko/.example.com/user/koko?

I have tried a couple of answers that I found here but it did not work.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
Lolak
  • 141
  • 1
  • 7
  • Should there be a trailing slash on the end of the redirected URL? Using the directive you've posted there would be a trailing slash, but in your "resulting URL" you've not included a trailing slash? – MrWhite Sep 21 '18 at 19:27

1 Answers1

1

It would be nice if you included what you tried and what didn't work.

Limit the characters you want to pass, otherwise you just copy untrusted data from the client. You may want to do something with the data after the name in the second pattern.

RedirectMatch 301 ^/user/([-a-zA-Z0-9]*)(.*)$ http://$1.example.com/user/$1
RalfFriedl
  • 3,108
  • 4
  • 13
  • 17