0

I created a shop and the url is like:
https://myshop.com

But my client asked me to add respective salers' id into the url so that they can do some analyses, so it would look like:
https://saler001.myshop.com

I don't know where should I start to do this trick, maybe something in the DNS settings? Currently I've suggested them using url query string, but they don't accept.

btw, this shop is on Shopify.

user3602859
  • 87
  • 1
  • 6

2 Answers2

0

You can parse the URL with the URL constructor, get the host name, then split it by a comma to get the subdomain.

const url = "https://saler001.myshop.com" //URL can be retrieved via `document.URL`

const id = new URL(url).hostname.split('.')[0].substr(5)
console.log(id)
Spectric
  • 30,714
  • 6
  • 20
  • 43
  • thanks for this method, but could you shed some light on the previous step? I'm not sure how to achieve this by DNS. – user3602859 May 13 '22 at 02:07
  • @user3602859 I would suggest checking [How to create a subdomain and how do they work?](https://stackoverflow.com/questions/18032285/how-to-create-a-subdomain-and-how-do-they-work) or asking another question if the problem you're encountering is specific. Posts should only be limited to 1 question. – Spectric May 13 '22 at 02:09
0

If you use Nginx, I think change vhost file can do it. (Apache also can do)

like there:

server {
    server_name ~^(?<name>\w+)\.myurl\.com$;

    location /admin {
        return 301 $scheme://www.myurl.com/sub=$name;
    }
}

If you can't change "HTTP proxy server", MUST check subdomain not work. if not work (find any subdomain will goto "www" your site), use @Spectric answer is right.

otherwise the "sub.google.com" only goto "sub.google.com" site, and not "www.google.com" / "google.com" site.

in there, you must use "Server API" check from site and do shop work, use like PHP or GoLange, etc.

UioSun
  • 59
  • 5