Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user friendly URLs without any file extensions? [closed]

I've been wondering for a long time how people manage to get their URLs to work without file extentions such as '.html' or '.apsx' on the end.

Look at this website for example:

http://www.axongarside.com/Communication
http://www.axongarside.com/Communication/Compleat
http://www.axongarside.com/Brand
http://www.axongarside.com/Brand/K3-Group

How have they accomplished this? The only method I can think of would be to create a new directory for each page and have an index page in each directory but this would be a huge hassle for a larger website. Is there any other way?

Thankyou

like image 740
user1636130 Avatar asked Feb 18 '23 22:02

user1636130


1 Answers

The three most common ways are to:

  • Use index pages (i.e. just create a directory and put an index.html file in it).
  • Use a rewrite engine (such as Apache's mod_rewrite) to map the URLs onto different files (this is a common approach in PHP-land).
  • Use a front controller script which processes the URLs for you (this is the usual approach for MVC frameworks).

The latter approach would use something like this in an Apache server configuration:

WSGIDaemonProcess example processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup example
WSGIScriptAlias / /hosts/example.com/application/wsgi.py

or

SetHandler fcgid-script
Alias / /hosts/example/application.fcgi/

For scripts using WSGI (Python) or FastCGI (Cross-language, that particular example was cribbed from a Perl application I'm writing) respectively.

The URL format would be handled by the script itself, and different frameworks take different approaches to the problem.

In Catalyst, this is done by providing attributes to subroutine names.

Dancer has its own route handler syntax.

Web::Simple uses subroutine prototypes.

Django uses a separate file containing a list of patterns.

like image 187
Quentin Avatar answered Mar 10 '23 10:03

Quentin