Home > Blockchain >  Can a slash in the url be taken as a query insntead of a path to a file directory
Can a slash in the url be taken as a query insntead of a path to a file directory

Time:12-31

By my limited understanding the " / " in an URL defines a path in the file directory the html is suppost to be pulled from.

So how is it possible that sites like reddit have URLs such as "reddit.com/u/username", where the slash doesn't define the file directory but is more so taken as a query that requests certain data from a user? Shouldn't you get an error back, that the site doesn't exist because it's not actually a file in the directory?

CodePudding user response:

Beacuse they use rewrite for pretty urls.

CodePudding user response:

By my limited understanding the " / " in an URL defines a path in the file directory the html is suppost to be pulled from.

No. It defines a path segment in the path requested from the HTTP server.

The HTTP server is software, it can be written to handle that path in any way the developer likes.

"Map the URL path onto a filesystem path" is only one (simple and common) way an HTTP server can handle paths in URLs.

"Pass it on to a server side program which reads the whole URL and acts in a custom way" is another. If you were using PHP then you might read $_SERVER['REQUEST_URI'].

"Convert the path segments into query string parameters on a different URL and effectively start the request handling again" is another. Typically, if you were using Apache HTTPD, you would use mod_rewrite for this.

"Have a custom webserver which maps them directly to functions" is another. It's a common approach when writing server side code in Node.js (e.g. with Express routes).

  •  Tags:  
  • php
  • Related