Click to See Complete Forum and Search --> : mod_rewrite problems, not parsing correctly


jbezanson
05-27-2008, 11:46 AM
I need a bit of help with url rewriting.

I have a couple possible url formats

site.com/Pages/Edit/1
site.com/Pages/List

I 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 controller
ErrorDocument 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/1

What 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.

rpgfan3233
05-27-2008, 12:53 PM
RewriteRule ^/([^/]+)/([^/]+)(/([^/]+))?$ index.php?controller=$1&action=$2&value=$4

A naive approach, but it should work for URLs along the lines of the following:
/Pages/List: index.php?controller=Pages&action=List&value=
/Pages/List/2: index.php?controller=Pages&action=List&value=2

/Pages/Edit: index.php?controller=Pages&action=Edit&value=
/Pages/Edit/7: index.php?controller=Pages&action=Edit&value=7

bluestartech
05-27-2008, 12:56 PM
try:

RewriteRule ^/*(\w*)/(\w*) /index.php?controller=$1&action=$2

note the leading slashes

jbezanson
05-27-2008, 01:01 PM
RewriteRule ^/([^/]+)/([^/]+)(/([^/]+))?$ index.php?controller=$1&action=$2&value=$4

A naive approach, but it should work for URLs along the lines of the following:
/Pages/List: index.php?controller=Pages&action=List&value=
/Pages/List/2: index.php?controller=Pages&action=List&value=2

/Pages/Edit: index.php?controller=Pages&action=Edit&value=
/Pages/Edit/7: index.php?controller=Pages&action=Edit&value=7

Thanks. This looks like what I need. I'll give it a try.