Mod-rewrite Hosting : Compare Hosting
Oops! No Hosting Plans Match Your Search
You've selected a combination of features that none of the web hosts we profile offer. We suggest you remove your last filter or reset & start again.
Ask Our Experts
Need help with your hosting? Tell us exactly what you are looking for and we’ll do our very best to help. Please allow one working day for a response.
Please fill in all fields.
Thanks! Your request has been sent. We'll reply within 24 hours.
Recommended Host for Mod-rewrite
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.
Better URL structure
A better URL structure for post 342 might be:
An even better structure would be:
The second one is better because it contains more information about the post itself: the title and its category. But even the first is a lot better than before, because its structure suggests that the post number 342 is a unique entity, a resource or document with its own existence.
Benefits of a better URL structure
Clean URLs are easier to remember, type, and transmit. People write down URLs, people say them over the phone to their friends, people hand-type them into emails (yes, instead of copy-and-paste — happens all the time).
URLs that include category and titling information (called a “semantic” URL) are good for SEO, because they provide Search Engines with information about the content.
Semantic URLs are implementation agnostic, meaning that the structure isn’t dependent on the web application or CMS. This makes it easier in the future to change the underlying technology as needed without breaking the URLs.
Because they are agnostic, pretty URLs identify a resource, not a way to get to it, which means that the underlying content can be edited, moved, changed, updated, or replaced without breaking the link between the identifier and the underlying resource.
How does mod_rewrite work?
Mod_rewrite is an Apache module that works at the level of the Apache web server. It handles incoming HTTP requests, and rewrites them according rules set up by the system’s administrators (either directly or programatically).
For example, the public URL of a blog post might be:
There might then be a rule (written in special code and regular expressions) which takes the first portion, matching it to a category, and the second portion and matching it to a post slug:
From there, the
index.php file takes over and pulls content out of the database based on the query strings.
How does mod_rewrite get used?
It is possible for a system administrator to manually write request rewrite rules for a webserver. But this is somewhat rare.
More typically, a Content Management System (or similar framework) will include code that automatically inserts rewrite rules into the relevant configuration files based on settings. If you’ve ever used WordPress — this is what happens when you select your Permalink structure in the
Admin -> Settings menu.
mod_rewrite and web hosting
Not all dynamic web applications require
mod_rewrite in order to achieve pretty URLs. For example, Ruby on Rails uses its own internal routing mechanism, so clean URLs are sent directly to the application as they come in.
However, many web applications and content management systems require it. This is especially true of most PHP-based CMSes like WordPress and Drupal.
It is a very common feature of Apache web servers, but don’t take it for granted. If you’re going to need it, make sure you select a hosting provider that supports Apache mod_rewrite, and allows your installed apps to write new rewrite rules.