Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Original URL looks something like domain.com/filename.php?id1=333&id2=444.

Desired rewritten URL is something like domain.com/my-rewritten-url.

I can imagine creating a lookup table with columns for the ids and a column for the rewrite string, but is this realistic/practical?

share|improve this question
This is exactly how Drupal.org functions, their URL Alias transforms the default query string (example.com?q=/path/to/page) to a "normal" URI path (example.com/path/to/page). The main thing is an Apache2 rewrite that changes the simple /path/to/page to index.php?q=/path/to/page. Then the index.php script handles the request by finding the page (via a set of menu rules). I wrote about this on this page snapwebsites.org/implementation/basic-concept-url-website in a rather extensive way... – Alexis Wilke Nov 8 '13 at 6:27
Hi, in my case however I only have numbers as the original URL and I want an associated piece of data, a string (a separate column found in the same database table) – Drewdavid Nov 8 '13 at 22:27
I guess the one problem you could run into is a bit of slowness, but numbers or strings it can work just fine. – Alexis Wilke Nov 9 '13 at 7:37
up vote 0 down vote accepted

This is very possible to implement. I have implemented it myself. It requires more than a rewrite rule though. It requires you to change the code that runs your web application. Here is how I have made it work:

  • A request comes in for /my-rewritten-url
  • A rewrite rule forwards it to `/filename.php?path=my-rewritten-url
  • The PHP script does a database query to get the parameter string (id1=333&id2=444) and the file name that should handle the request (show-this-page-type.php)
  • It parses that parameter string and puts the values into the parameter map
  • It dispatches the request to show-this-page-type.php

The downsides are:

  • It adds an extra database query (caching can help)
  • It requires that your website be powered by a single script that may have to dispatch requests out to other scripts
  • It breaks analytics that are rely on the existence of parameters in the URLs or the name of the script. (It is much harder to determine page type, for example.)
share|improve this answer
Hi, thank you – this is very helpful and will assist in determining the ROI of this activity :) – Drewdavid Nov 7 '13 at 22:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.