javascript - How to remove the file name after the domain name
高洛峰
高洛峰 2017-06-12 09:28:55
0
8
780

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/

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(8)
小葫芦
var url = 'http://www.yx86911.com/xxx/index.html'
url.substr(0, url.lastIndexOf('/'))
黄舟

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/"
我想大声告诉你
location.origin
漂亮男人

window.location.origin

漂亮男人

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

学习ing

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

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

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!