Last updated: March 5, 2019
The Best Mod-rewrite Hosting: Who’s The Best For Your Site? [Updated: 2019]
What is Mod_Rewrite Hosting?
mod_rewrite module is an Apache module that provides the ability to rewrite URL requests as they are made. This allows website users to see and interact with simple or “pretty” URLs instead of the complicated ones created by a web application.
You probably use URLs everyday, without thinking much about what is actually going on “under the hood.” To understand how Apache
mod_rewrite works, and why you’d need it, we need to look at what a URL is and how dynamic web applications work.
Uniform What Locator?
A URL is a Uniform Resource Locator.
In the early days of the internet, the idea was that you were looking for some specific file, document, or image: a resource. The resource existed on some other computer, you just needed to know:
- The name of the computer it was on
- The path to the file itself.
The name of the computer is what we now call “the domain name,” and evrything after the .com or .net (or .whatever) was the path to the file.
Web applications and URLs as query strings
Eventually, people started serving more than static documents and resources on their web server. People started building dynamic websites that would pull their content out of a database.
Imagine a typical CMS-driven blog website. Its natural, and desirable, to think of a single blog post as a document or resource. But that isn’t really the way the computer is storing it.
The is some file, perhaps
index.php, that includes code to take an input id-number, make a call to the database, and then display the content of the post to the user.
The “real” URL for the blog post might be:
/index.php portion specifies the filename, and the
?post=342 is an input specifying that you want post number 342.
There are two problems with that.
The practical problem is that the URL doesn’t contain any real information. This makes it hard to remember and unattractive to read. It just looks like gibberish. It gives search engines no information about the content of the post, either.
The philosophical problem, or conceptual problem, is that it breaks the idea that a post is a resource unto itself, a document. The semantic meaning of the URL is: “Show me the document at index.php, with the results of post=342 included.” This is not what is actually intended, though.