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 :


index.php?lang=ar&option=a&option_m=b

and variable option&option_m are optional

so i want convert this url to


/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 :


/ar/a/b/input1-value/input2-value

thankx ?

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

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

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 ?

hello mr.dklynn …

so it’s not possible by mod-rewrite ?

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