SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mod rewrite rules help please

    hello ,
    i made a script .. and i want to make it's all urls to be seo friendly ..

    my current php urls is :
    Code:
    index.php?lang=ar&option=a&option_m=b
    and variable option&option_m are optional

    so i want convert this url to
    Code:
    /ar/a/b
    
    or
    
    /ar/a
    
    or
    
    /ar
    and i want ask about if the page have form with GET Action ,, how to accept the query string and add it in the url automaticly .. such as :

    Code:
    /ar/a/b/input1-value/input2-value
    thankx ?

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

    If you're familiar with creating functions with optional arguements, it's much the same. Create regex to require the required part(s) then make the following optional IN ORDER that you require them to be present. That's done by making the entire optional part optional then, within it, requiring the first to be present and making the remainder optional, e.g.,

    ^{required}(/({optional}))?$ where

    {required} appears to be your 'ar' and
    {optional} would be {required2}(/({optional2}))?

    That nesting continues until you run out of $n values (you can only have n=1 to n=9 so you have hit the max with your four optional values).

    If this is not what's intended, you'll need to break-up your mod_rewrite to handle the different cases separately (and provide "markers" to distinguish which case you're handling).

    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

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello mr.dklynn ..

    so it's not possible by mod-rewrite ?

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

    Yes, as above, it IS possible!

    Looking again at your first post, the last two variables should already be in a query string. Therefore, you do NOT have to deal with that EXCEPT that you must take care to APPEND to that string with your new key/value pairs. The Query String Append (QSA) flag is designed to do just that!

    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

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx alot mr dklynn ,

    ok i understood your idea .. but i don't know how to write it in mod_rewrite .. i'm beginner to use mod_rewrite ..

    so if it possible to help me and write the .htaccess rules ?

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

    Yes, I'd be glad to help you learn to write mod_rewrite for this, however, I don't do "coding for free" (work for "script kiddies") so I require that you make an attempt. Use my signature's tutorial as it will make ANYONE an instant expert. Include the "optional" information above and you're all set. Of course, I'm here to help you improve your code to make it "perfect."

    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
  •