Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite question

         

MattC

9:35 pm on Jun 29, 2008 (gmt 0)

10+ Year Member



I have a question about mod_rewrite. I am working on implementing "clean" URL's for my web application. The format I want is:

example.com/app/param1-value1/param2-value2/

to rewrite to

index.php?param1=value1&param2=value2

and so on and so on. The problem is that my application uses a "module" parameter on every page, so I'd like a special exception for it to make it more user-friendly. I want the first param-value pair in the URL to assume the param name is "module", so it can be omitted in the URL. Example:

example.com/app/modname/param1-value1/param2-value2/

becomes

index.php?module=modname&param1=value1&param2=value2

I've tried many ways of doing this, but being able to support an unlimited number of parameter-value pairs AND the special "module" case is tricky. Is there a way to do this with the regular RewriteRule and RewriteCond commands rather than an external script? Can anyone provide a solution or starting point for me?

Much thanks,
-Matt

jdMorgan

10:16 pm on Jun 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I've tried many ways of doing this, but being able to support an unlimited number of parameter-value pairs AND the special "module" case is tricky.

If "/app/" at the beginning of the local URL-path implies that whatever follows "/app/" is to be used as the value for the modname, then this presents no particularly-difficult challenge. More problematic is the statement, "able to support an unlimited number of parameter-value pairs."

If you intend to use mod_rewrite, then there *will* be a challenge, though not an insurmountable one, if you try to use more than five name/value pairs. This is because of the nine-backreference-creation-limit for a single RewriteRule or RewriteCond.

As I did in an earlier thread today, I'll recommend that you start with Changing Dynamic URLs to Static URLs [webmasterworld.com]. Then post your best-effort code as a basis for discussion.

Jim