search

Home  >  Q&A  >  body text

Replace www in URL with wildcard subdomain

Is there any way to

www.domain.com/new-mexico/albuquerque/businessname-513526.html

is replaced with:

businessname.domain.com/new-mexico/albuquerque/businessname-513526.html

This means "www" will be replaced by the business name. This should be simple but I don't know how to implement it.

P粉336536706P粉336536706231 days ago432

reply all(1)I'll reply

  • P粉713846879

    P粉7138468792024-04-05 12:21:30

    Sounds like you may need to use str_replace

    $old_domain = "www.domain.com/new-mexico/albuquerque/businessname-513526.html";
    $new_domain = str_replace("www.", "businessname.", $old_domain); //我选择在www之前加上点号,以防URL中还有另一个www

    reply
    0
  • Cancelreply