Home  >  Q&A  >  body text

javascript - How to remove the file name after the domain name

My website is 'http://www.yx86911.com/Defaul...' or 'http://www.yx86911.com/Defaul...' How to remove the following to get 'http:// www.yx86911.com'

Thank you for your answers

Sorry for not making it clear, the folder still needs to be left.
For example, http://www.yx86911.com/xxx/in... To get http://www.yx86911.com/xxx/

高洛峰高洛峰2686 days ago784

reply all(8)I'll reply

  • 高洛峰

    高洛峰2017-06-12 09:30:55

    var url = 'http://www.yx86911.com/xxx/index.html'
    url.substr(0, url.lastIndexOf('/'))

    reply
    0
  • 黄舟

    黄舟2017-06-12 09:30:55

    I think what he means is to use regular expressions to match addresses.
    Sir, do you want to match only the first folder or all folders except files?

    var a = 'http://www.yx86911.com/xxx/555/index.html';
    a.match(/http:\/\/.+com\/(.+?\/)?/)//匹配出"http://www.yx86911.com/xxx/"
    a.match(/http:\/\/.+com\/(.+\/)?/)//匹配出"http://www.yx86911.com/xxx/555/"

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-12 09:30:55

    location.origin

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-12 09:30:55

    window.location.origin

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-12 09:30:55

    You can just change the file name to index.aspx. The default main file of the website is index

    reply
    0
  • 学习ing

    学习ing2017-06-12 09:30:55

    This is usually configured in Apache, IIS or Nginx. The configuration method of Apache is:
    Enable the mod_rewrite module

    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    1
    

    Change AllowOverride None to AllowOverride All

    reply
    0
  • PHP中文网

    PHP中文网2017-06-12 09:30:55

    var url = new URL("http://www.yx86911.com/123/");
    console.log(url.origin+url.pathname.replace(/[\/]*$/,''))

    reply
    0
  • PHP中文网

    PHP中文网2017-06-12 09:30:55

    This is aspx, .NET, go check out UrlRewrite, or use asp.net MVC

    reply
    0
  • Cancelreply