[RESOLVED]mod rewrite ... again

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I still have no idea how the hell mod rewrite works, I have the following code:

APACHE Code: [ Select ]
Options +FollowSymLinks
RewriteEngine on
 
RewriteRule ^/(.*)/(.*)/update$ create.php?table=$1&data=$2&action=update [L]
RewriteRule ^/(.*)/create$      create.php?table=$1&action=create [L]
  1. Options +FollowSymLinks
  2. RewriteEngine on
  3.  
  4. RewriteRule ^/(.*)/(.*)/update$ create.php?table=$1&data=$2&action=update [L]
  5. RewriteRule ^/(.*)/create$      create.php?table=$1&action=create [L]


and all I want to do is the following:

I want to type in something like "http://www.mysite.com/user/create" and it must then take me to "http://www.mysite.com/create.php?table=user&action=create"

Same with "http://www.mysite.com/user/14/update" that must take me to "http://www.mysite.com/create.php?table=user&data=14&action=update"

I tried the code posted above but all I get is "The requested URL /user/14/update was not found on this server."

Please can someone help me here, I have no idea what's wrong with this.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Hahaha, okay, nevermind, I figured it out, the correct code doesn't need that first slash there. It should be as follows:

APACHE Code: [ Select ]
RewriteRule ^(.*)/(.*)/update$ create.php?table=$1&data=$2&action=update [L]
RewriteRule ^(.*)/create$      create.php?table=$1&action=create [L]
  1. RewriteRule ^(.*)/(.*)/update$ create.php?table=$1&data=$2&action=update [L]
  2. RewriteRule ^(.*)/create$      create.php?table=$1&action=create [L]
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

That first slash is tricky, especially if you're used to working with the REQUEST_URI which usually starts with the slash.

For the longest time I just worked around trying to remember whether the slash is included or not by using a "zero-or-one" quantifier.

APACHE Code: [ Select ]
RewriteRule ^/?marker(.+)\.html$ ...

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 116 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.