How do /v/, /r/ urls work?

22    08 Jul 2015 20:08 by u/PervertedObserver

I've been wondering this lately. Things like Voats voat.co/v/programming for example.

Do they have a separate folder or webpage for each subverse or subreddit, or is it more similar to a PHP $_GET variable that changes what's displayed on the page based on the value?

10 comments

18
14

You can link to lines you know: Lines 588 to 592

7

Neat, I didn't know.

2

wow interesting, thought voat was built on python, not something "uncool" like c# :p

0

C# is very cool. What makes people think it's "less cool" than Python is that it's a language that has prerequisites you need to understand in order to use it properly, so it's not as easy to immediately get into making it less attractive for hobbyists. But in any technical terms it is thousands of times "better" than Python for a myriad of reasons.

I also immediately assumed it was made in Python, so I was pleasantly surprised to see that it was not.

10

It's called Semantic URLS. Sometimes called friendly URLS or clean URLs. The web application looks at the URL, breaks it down into its individual parts and fetches the corresponding data. If you were to implement this through PHP, you would parse "$_SERVER['REQUEST_URI']".

5

Is URL Routing a similar technique? Because thanks to /u/Stavon, I found this article

4

Same thing, different term. I would tend to think of URL Routing as being a little more specifically calling for a dynamic, programatic solution, but these days that would almost be a distinction without a difference.

1

Yes. URL Routing is just another name for it. If you look at the "Real Code" section of that article you'll see that he is taking "$_SERVER['REQUEST_URI']", stripping off the base path, and then parsing out the strings that are between the forward slashes.

1

Not having looked at the source, I assume there will be a central handler function behind this, and when requesting "/v/<some-regex>/" it looks for the name and if it exists returns the subverse for use in the templates.