aspnetguy Posted May 27, 2008 Share Posted May 27, 2008 I need a bit of help with url rewriting.I have a couple possible url formatssite.com/Pages/Edit/1site.com/Pages/ListI have the following .htaccess file Options +FollowSymLinks +ExecCGI<IfModule mod_rewrite.c> RewriteEngine On # uncomment the following line, if you are having trouble # getting no_script_name to work #RewriteBase / # If requested resource does not exist as a file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2 </IfModule># big crash from our front web controllerErrorDocument 500 "<h2>Application error</h2>website failed to start properly" this file works great for site.com/Pages/List style urls but fail for site.com/Pages/Edit/1What I want is site.com/{1}/{2}/{3} where it translates to site.com/index.php?controller={1}&action={2}&value={3}Can someone help me out? Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2008 Share Posted May 27, 2008 It looks like you left out the third parameter, wouldn't you just add that to the end?RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2&value=$3 Link to comment Share on other sites More sharing options...
aspnetguy Posted May 27, 2008 Author Share Posted May 27, 2008 It looks like you left out the third parameter, wouldn't you just add that to the end?RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2&value=$3The problem is there isn't always 3 parameters. I know my current file doesn't handle 3 it only handles 2 right now. How do I set it up to hanlde either 2 or 3 parameters (i.e. $3 doesn't always exist.) Link to comment Share on other sites More sharing options...
justsomeguy Posted May 27, 2008 Share Posted May 27, 2008 I'm not sure, I haven't done a lot of htaccess stuff. Does it give an error if there isn't a third parameter? You might be able to add more than one rule and it might match the first one that succeeds, not sure if that's how it works or not.RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2&value=$3RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2 Link to comment Share on other sites More sharing options...
aspnetguy Posted May 27, 2008 Author Share Posted May 27, 2008 I'm not sure, I haven't done a lot of htaccess stuff. Does it give an error if there isn't a third parameter? You might be able to add more than one rule and it might match the first one that succeeds, not sure if that's how it works or not.RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2&value=$3RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2I tried successive rules and it gives errors (not sure what errors now). After that I resorted tot he file I have now. My plan was if there were three parameters it would do this index.php?contoller=Pages&action=Edit/1 except my current file does this index.php?contoller=Pages/Edit&action=1. I did get this sorted out though and I also have a suggestion from another forum that with assigned value= if there isn't a 3rd parameter. I let you know how that works out when I get a chance to test it. Thanks for the help. Link to comment Share on other sites More sharing options...
Synook Posted May 28, 2008 Share Posted May 28, 2008 Try also adding the $ terminating character to the end of the first parameter - I found that sometimes the engine can get confused between the first and second parameters if you omit it. Link to comment Share on other sites More sharing options...
boen_robot Posted June 7, 2008 Share Posted June 7, 2008 Wouldn't a clean PHP URL handler clear up this problem? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.