Web pages without file extension

I can see on this website that the url is http://stackoverflow.com/questions/ask

. There is no file extension after that, and if the request was a folder and inside that index like index.aspx it looks like http://stackoverflow.com/questions/ask/

.
How do they do it? How do they renew the expansion? Thanks, Phantom

+3


source to share


2 answers


How do they do it? How do they renew the expansion?

The extension does not disappear, but there is simply no extension. In the fairly recent (say 15 years) world of web programming, a web application is no longer a bunch of actual directories of actual files. Nowadays web applications have many different architectures and many patterns apply. The web server can also provide this functionality through the URL rewriting extension. Both are usually combined.

The most common pattern that implements this is Front Controller . The idea is that ALL requests are sent to the same entry point. This entry point can then decide which code to execute to generate the output. Most MVC frameworks use the URI after the controller name (usually index.php) to determine what type of controller and controller method to invoke, although these are usually customizable these days.



In the example, http://stackoverflow.com/questions/ask

one possible scheme:

  • The web server rewrites the url http://stackoverflow.com/index.php/questions/ask

  • index.php as front controller then parses URI segments after its name which /questions/ask

  • Then it constructs an instance of the class questions

    and calls its methodask

  • The method generates output, which is then sent back in response to the request
+6


source


They use something called rewrite rules, perhaps in the .htaccess file in the root of the website. They added something like this .htaccess file

RewriteEngine On # Enable rewrite engine



RewriteRule ^ ask /? $ questions.php? questionID = {1} [NC, L]

+3


source







All Articles