mod_rewrite problems.

Discussion in 'Apache' started by justinbezanson, May 27, 2008.

  1. #1
    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"
    Code (markup):
    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.
     
    justinbezanson, May 27, 2008 IP
  2. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #2
    Some scripts use this trick : they let index.php capture the page name, and do a PHP or MySQL processing about finding the real link (for instance, the WordPress script).
     
    ForumJoiner, May 31, 2008 IP
    justinbezanson likes this.
  3. justinbezanson

    justinbezanson Peon

    Messages:
    160
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I ended up using a similar technique as I couldn't get a regular expression to do what I needed.
     
    justinbezanson, May 31, 2008 IP