Skip to content Skip to sidebar Skip to footer

How To Get User Friendly Urls Without Any File Extensions?

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: htt

Solution 1:

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.

Solution 2:

If you are using Apache you can use the .htaccess file to remove the .html extension like so:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

To remove the .html extension from the url just link to the page without .html

<ahref="http://www.mysite.com/page">linkhere</a>

Solution 3:

If you are using Apache HTTP Server you should check mod_rewrite capability. IIS also has a similar URL rewrite feature.

Post a Comment for "How To Get User Friendly Urls Without Any File Extensions?"