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

In my PHP based web application, there's a form that generates a URL according to the user's selection. The form has 7 different fields, each one of them affects the final URL, none of them is mandatory.

The final URL can be:


or just:


these URLs should be rewritten to-




Is it possible to create a single rewrite rule that will cover these variations? I'd hate to create different rewrite rule for every possible scenario, it'll take forever...

I'm currently developing the app on a Windows machine with IIS 7.5, but will eventually deploy it to an Apache server.

Is it possible in both? I currently need to solve it for the IIS environment, and later on for Apache.

share|improve this question
For the Apache side of things, see stackoverflow.com/questions/117931 – Peter Taylor Jan 15 '12 at 8:04
@PeterTaylor Thanks! – jitzo Jan 16 '12 at 2:33

From http://stackoverflow.com/questions/117931 Use the following rewrite rule to forward the entire URL into your script:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Then inside your index.php script, get the 'q' parameter, and split it on slashes. Put the values into a map.

$pathmap = ();
if ($_GET["q"]){
    $path = split("/", $_GET["q"]);
    for ($i=0; $i+1<count($path); $i++){
        $pathmap[$path[$i]] = $path[$i+1];
share|improve this answer

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.