From: Matthew M. <ma...@tu...> - 2005-09-19 15:31:34
|
Greetings, While working on a new module (Web Page) I hit a snag with mod_rewrite. Normally mod_rewrite works like so: Apache, via a .htaccess file that comes with 1.x, sees this: webpage/view/6 and translates it to index.php?module=webpage&action=view&id=6 The variable names 'action' and 'id' are hardcoded in. There is even a function in PHPWS_Text that you can send just the module name, action call, and id and it will create the link depending on whether mod_rewrite is enabled. This is the snag. Web Page, unlike 0.10.x, allows different pages. So I need a link to page 2 to look like this: index.php?module=webpage&action=view&id=6&page=2 or via mod_rewrite webpage/view/6/2 To do this in the .htaccess file, I had to define another line to look for a 4th parameter. I called it 'sub1' because I needed something generic. Here is the .htaccess file: RewriteRule ^(\w+)/(\w+)$ index.php?module=$1&action=$2 [NC] RewriteRule ^(\w+)/(\w+)/(\w+)$ index.php?module=$1&action=$2&id=$3 [NC] RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)$ index.php?module=$1&action= $2&id=$3&sub1=$4 [NC] This solves the problem, but it got me wondering about the mod_rewrite flexibility. Using the above solution: 1) the command directive in any module HAS TO be named 'action' 2) the id HAS TO be named 'id', not page_id, article_id, etc. 3) all other variables would now be variations of sub(n) which is a departure from the previous naming structure. What I was thinking was making this MORE generic in one of two ways. First way: ----------------------------------------------------------- Every variable besides the module, would be var + n So... webpage/view/6/2 would translate index.php?module=webpage&var1=view&var2=6&var3=2 What is nice about this is it keeps the link size down. The downside is that you are stuck checking for or translating the various var1, var2, etc. to usable variable names. Second way ------------------------------------------------------------- index.php?module=webpage&user_action=view&webpage_id=6&page_number=2 becomes: webpage/user_action/view/webpage_id/6/page_number/2 Now we have a longer link but we get our custom request variable names back. It would definitely be easier to code this way without having to parse 'var(n)' get variables. So my question to you is: which way, as a site admin and/or developer would you rather see? Which ever way we go I will design the .htaccess and phpws_text function to correspond. Thanks for your help, Matt -- Matthew McNaney Electronic Student Services Appalachian State University http://phpwebsite.appstate.edu |