Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts

    Simple Mod Rewrite Question

    Hi,

    I've been recently reading up on Apache's mod rewrite feature. At the moment I'm a bit puzzled about how it works exactly but I'll figure it out eventually. Anyways, my question is do I have to write a rewrite rule for every page?

    For instance, say I want news.php?cat=tech&id=2 to be like /news/tech/2/
    and tutorials.php?cat=html&id=65 to be like /tutorials/html/65/, would I have to have a separate rewrite rule for each? 2 different pages = 2 different rules?
    Or is there a one way all page sort of thing?

    I'm guessing its a rule for every page...

    *edit*
    One more thing, do I still use $_GET (ex: $_GET['cat']) for the variables? Or do I need to explode it?
    Last edited by fl00d; 10-30-2007 at 02:32 AM.

  • #2
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    No, you can write a rule using Regex that handles a wide variety of files according to parameters you define.
    here is an example:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]
    Keep reading.

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Useful Resource: http://forum.modrewrite.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •