1

So it's kind of a dumb question but I'm really wondering how I can make this :

  • user type www.mydomaine.com/something
  • page display : something

and it does with anything he type after the domain name

I've no idea how I could do that. I know I can get an info from an URL with jQuery but how can i remove the thing like index.html in the url? My guess would be with the htaccess?

Also, there won't be any other page but this with some design, how can I make sure someone doesn't go anywhere else but on the page that display what he wrote after the domain name?

I hope that's clear, thanks for reading and your answers ! Pierre

justpierre
  • 13
  • 2

1 Answers1

1

When creating an anchor tag and adding an href (or making a URL) I needed the URL to have a protocol (http or https), so I made a validation to add it, and then you can access the parameters of the URL easier.

Also, if you want to remove the / from the pathname you can use a .replace('/', '') when using parser.pathname

For removing index.html from the URL, you can split the path and get only the first element, or the ones you need f.e. parser.pathname.split('/')[0]

var myUrl = "www.mydomaine.com/something"
if (!myUrl.startsWith('http')) myUrl = 'http://' + myUrl;

var parser = document.createElement('a');
parser.href = myUrl;
console.log(parser.pathname);

// Other option
var theUrl = new URL(myUrl);
console.log(theUrl.pathname);

I used this as a reference.

Pietro Nadalini
  • 1,722
  • 3
  • 13
  • 32