Mobile app version of vmapp.org
Login or Join
Berumen354

: Dynamically rewrite URLs upon the user's selection - is it possible? 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

@Berumen354

Posted in: #Iis #Iis7 #ModRewrite #UrlRewriting

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:


/field1/user_setting_of_field1/field3/user_setting_of_field3/field6/user_setting_of_field6/


or just:


/field4/user_setting_of_field4


these URLs should be rewritten to-


/results.php?field1=user_setting_of_field1&field3=user_setting_of_field3&field6=user_setting_of_field6


and:


/results.php?field4=user_setting_of_field4


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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Berumen354

1 Comments

Sorted by latest first Latest Oldest Best

 

@Eichhorn148

From 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= [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];
$i++;
}
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme