SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot dereko's Avatar
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Restructuring ReWrite rule

    I have the following rewrite rules that work fine but is there a better way to do it?

    Code:
           RewriteRule ^/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=$1&var1=$2&var2=$3&var3=$4
           RewriteRule ^/([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=$1&var1=$2&var2=$3
           RewriteRule ^/([^/]*)/([^/]*)/$ /index.php?page=$1&var1=$2
           RewriteRule ^/([^/]*)/$ /index.php?page=$1
    This for example allows for 3 extra variables

    turning

    example.com/clients/a/b/c/
    into
    example.com/index.php?page=clients&var1=a&var2=b&var3=c

    So if I want it to allow for 4 variables I need to add another rewrite rule and 5 another and so on.

    My question is, is there a single line recursive way of writing this rewrite rule to allow for any amount of extra variables?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    o,

    Yes, and there's code for that in my signature's tutorial, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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