Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove protocol, domainame, domain and file extension from URL

let say that in our websites we can have urls like:

http://domainame.com/dir/one-simple-name.html
https://dmainame.com/mail/send.php
https://dmainame.com/mail/read

etc..

So i would like to retrieve

dir/one-simple-name
mail/send
mail/read

Whats the best way to achieve it?

like image 842
Toni Michel Caubet Avatar asked Nov 29 '22 15:11

Toni Michel Caubet


2 Answers

Everybody stand back! I know regular expressions! Try this one:

var my_location = window.location.toString().match(/\/\/[^\/]+\/([^\.]+)/)[1];
like image 168
iblue Avatar answered Dec 10 '22 21:12

iblue


I would recommend doing this by,

var url = "https://www.somegoodwebsite.com/happy/ending/results/index.html";
console.log(url.replace(/^.*\/\/[^\/]+/, '') ); 

;

Result:
happy/ending/results/index.html
like image 39
Sanjay Pradeep Avatar answered Dec 10 '22 19:12

Sanjay Pradeep