AboutBlogContact
Web DevelopmentMay 18, 2001 3 min read 124Updated: June 22, 2026

URLs are User Interface: The 2001 Guide to Apache mod_rewrite

AunimedaAunimeda
📋 Table of Contents

In the early months of 2001, the web is maturing. We're moving away from the 'wild west' of chaotic query strings. If your site's URLs are full of ? and & symbols, you're making a mistake. Not only are they ugly to users, but search engines like Google and AltaVista often struggle to index them deeply.

The tool of choice is mod_rewrite, famously known as the 'Swiss Army Knife of URL manipulation'. It's powerful, it's regex-based, and it can be a total nightmare if you don't understand the flags.

The Basic Rewrite Engine

To use mod_rewrite, you must enable it in your httpd.conf or your local .htaccess file. The core directive is RewriteEngine On.

# In your .htaccess file
RewriteEngine On
RewriteBase /

# Goal: Transform /products/123 to /product.php?id=123
RewriteRule ^products/([0-9]+)$ /product.php?id=$1 [L]

That single line does a lot. The ^products/([0-9]+)$ is a regular expression. The parentheses () capture the numeric ID, and $1 injects it into the destination URL. The [L] flag tells Apache to stop processing rules if this one matches.

Creating a 'Front Controller'

As we move toward more complex PHP and Perl applications, the 'Front Controller' pattern is becoming the industry standard. This involves routing all requests to a single index.php file that handles the logic.

# Route everything that isn't a real file or directory to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]

The QSA (Query String Append) flag is crucial here. It ensures that if the user visits /news/latest?sort=desc, the sort=desc isn't lost during the rewrite.

Handling Domain Normalization

Professional sites in 2001 should not serve the same content on both example.com and www.example.com. This causes 'canonical URL' issues. Use mod_rewrite to force the www prefix.

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

The R=301 flag tells the browser (and search engines) that this is a 'Permanent Redirect'. This is essential for maintaining your search rankings.

The Regex Trap

Regex is greedy by default. If you aren't careful, you'll create rewrite loops. Always test your rules one by one. If you're on a shared host with an old version of Apache 1.3, you might find that certain variables like %{REQUEST_URI} behave slightly differently than on Apache 2.0.

Remember that mod_rewrite works in 'internal' redirects. The user sees a clean URL in their address bar, but your script sees the ugly query strings it needs to function. This is the hallmark of a professional 2001-era web architect.


Aunimeda develops websites and web applications for businesses - corporate sites, e-commerce, portals, and custom platforms.

Contact us to discuss your web project. See also: Web Development, E-commerce Development

Read Also

Stripe: Finally, a Payments API for Developersaunimeda
Web Development

Stripe: Finally, a Payments API for Developers

Accepting credit cards on the web has always been a nightmare of merchant accounts and clunky gateways. Stripe is here to fix that with a few lines of code.

Hulu: High-Quality Video in the Browseraunimeda
Web Development

Hulu: High-Quality Video in the Browser

NBC and Fox have teamed up to launch Hulu. It's high-quality TV, it's in the browser, and it's free (with ads). Is this the future of television?

Django 0.95 Internals: Custom Request/Response Hooks via Middleware (2006)aunimeda
Web Development

Django 0.95 Internals: Custom Request/Response Hooks via Middleware (2006)

Deep dive into custom request/response hooks in Django 0.95. Learn how to manipulate headers, handle authentication, and transform responses globally.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Web Development

Get Consultation All articles