Jump to content
xisto Community
Sign in to follow this  
iGuest

Additional Parameters In mod_rewrite URLs How to pass additional parameters in mod_rewrite urls

Recommended Posts

Hi everyboy, Oflate I faced great difficulty to pass additional parameters in mod_rewrite urls. I'll tell it from the beginning to help you understand exactly what was the problem. I have urls in my webpages which are like this one:


mydomainname.com/index.php?category=category_name

And I wanted the url to look like this ( a more search engine friendly form):


mydomainname.com/category/category_name.htm

So I applied mod_rewrite rule as per usual practice.


RewriteEngine OnRewriteRule ^category/([^/\.]+).htm$ index.php?category=$1& [L]

In my earlier post in a similar topic here , I have made it clear what these notaions stand for. Here is the link to my previous post. Now when I require to pass an additional parameter like :


mydomainname.com/index.php?category=category_name&country=country_name

I found it was not that all easy. I got some idea about how to accomplish that in a post at doriat.com but it did not work for me. So I had to try for something different. Finally, I passed the additional parameter with the mod_rewrite url in this way:


mydomainname.com/category_name|country_name.htm

without making any change in the aforesaid RewriteRule. And used


$qry_string=$_GET["category"];

to retrieve the value stored there. Then I exploded the $qry_string variable to seperate the stored value into two parts.


$qry_string_exploded=explode("|",$qry_string);

And finally I retrieved the values like


$category= $qry_string_exploded[0];$country=$qry_string_exploded[1];

I think, this is a simple solution to pass additional query strings in mod_rewrite urls. Regards, Sid


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.