You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Kevin Smith <ke...@netsmith.ltd.uk> on 2005/11/19 13:33:08 UTC

[users@httpd] Apache RewriteRule

Hi All,

Wonder if someone can work this one outt, I'm a bit stumped.

I have the following RewriteRule:

RewriteRule ^/product_category/([0-9]+)\.html\?source\=(.*)     
/product_category.php?top_cat_id=$1&source=$2

This is meant to rewrite this URL:
    http://www.foobar.com/product_category/22.html?source=foobar

Into this URL:
    http://www.foobar.com/product_category.php?top_cat_id=22&source=foobar

However, it doesn't get the data after the source= parameter.

It all works fine if I do this:
    RewriteRule ^/product_category/([0-9]+)     
/product_category.php?top_cat_id=$1

So, it seems there something no right trying retrieve parameters after 
.html extension?

Any ideas?

Regards,

Kevin



Re: [users@httpd] Apache RewriteRule

Posted by Kevin Smith <ke...@netsmith.ltd.uk>.
Hi Joshua,

Thanks for the pointer! :) This is what made it work in the end, for 
anyone who wants to know.

RewriteRule ^/product_category/([0-9]+)\.html(.*)?      
/product_category.php?top_cat_id=$1&source=$2 [NC,QSA,L]

Regards,

Kevin

Joshua Slive wrote:
> On 11/19/05, Kevin Smith <ke...@netsmith.ltd.uk> wrote:
>   
>> Hi All,
>>
>> Wonder if someone can work this one outt, I'm a bit stumped.
>>
>> I have the following RewriteRule:
>>
>> RewriteRule ^/product_category/([0-9]+)\.html\?source\=(.*)
>> /product_category.php?top_cat_id=$1&source=$2
>>
>> This is meant to rewrite this URL:
>>     http://www.foobar.com/product_category/22.html?source=foobar
>>
>> Into this URL:
>>     http://www.foobar.com/product_category.php?top_cat_id=22&source=foobar
>>
>> However, it doesn't get the data after the source= parameter.
>>
>> It all works fine if I do this:
>>     RewriteRule ^/product_category/([0-9]+)
>> /product_category.php?top_cat_id=$1
>>
>> So, it seems there something no right trying retrieve parameters after
>> .html extension?
>>     
>
> If you look in the docs for RewriteRule, you'll see a special box
> discussing the query string.  It tells you that RewriteRule doesn't
> match against the query string.  You need a RewriteCond to do that. 
> In your particular case, it seems like all you want is to copy the
> query string to the new url and add something else.  In that case, the
> [QSA] options (for Query String Append) is all you need:
> RewriteRule ^/product_category/([0-9]+)\.html
> /product_category.php?top_cat_id=$1 [QSA]
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>   

Re: [users@httpd] Apache RewriteRule

Posted by Joshua Slive <js...@gmail.com>.
On 11/19/05, Kevin Smith <ke...@netsmith.ltd.uk> wrote:
> Hi All,
>
> Wonder if someone can work this one outt, I'm a bit stumped.
>
> I have the following RewriteRule:
>
> RewriteRule ^/product_category/([0-9]+)\.html\?source\=(.*)
> /product_category.php?top_cat_id=$1&source=$2
>
> This is meant to rewrite this URL:
>     http://www.foobar.com/product_category/22.html?source=foobar
>
> Into this URL:
>     http://www.foobar.com/product_category.php?top_cat_id=22&source=foobar
>
> However, it doesn't get the data after the source= parameter.
>
> It all works fine if I do this:
>     RewriteRule ^/product_category/([0-9]+)
> /product_category.php?top_cat_id=$1
>
> So, it seems there something no right trying retrieve parameters after
> .html extension?

If you look in the docs for RewriteRule, you'll see a special box
discussing the query string.  It tells you that RewriteRule doesn't
match against the query string.  You need a RewriteCond to do that. 
In your particular case, it seems like all you want is to copy the
query string to the new url and add something else.  In that case, the
[QSA] options (for Query String Append) is all you need:
RewriteRule ^/product_category/([0-9]+)\.html
/product_category.php?top_cat_id=$1 [QSA]

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org