Forwarding query string with rewrite rule - .htaccess

I'm trying to write a rewrite rule but I've some serious problems with forwarding query string.
I also tried [QSA] flag but it didn't work.
Following the correct request:
/localhost/registry/registry.php?id=something&password=somethingelse&uri=whatever
And I would change into something like this:
/localhost/registry/register
with the same post query (id=something&password=somethingelse&uri=whatever).
At this point, my .htaccess would modify the above request in the following one:
/localhost/registry/registry.php?request=register&id=something&password=somethingelse&uri=whatever
Then, I tried the following rewrite rule in my .htaccess:
RewriteRule ^register$ http://localhost/registry/registry.php?request=$0&$1 [QSA]
But, after the last '&', nothing is showed and the $1 variable is empty.
What kind of rewrite rule I have to write?
Thanks in advance.
!!! SOLUTION !!!
RewriteRule ^register$ /registry/registry.php?request=$0 [QSA]

RewriteRule ^register$ /registry/registry.php?request=$0 [QSA]
if you go to http://localhost/registry/register?id=1, then query string would be(from php) :
array(2) {
["request"]=>
string(8) "register"
["id"]=>
string(1) "1"
}

Related

How to rewrite my url parameter with htaccess?

I have the following url:
http://example.com/folder/index.php?module=centrale&DIO0=1
I need this page to be availeble with the following URL format:
http://example.com/folder/centrale/?DIO0=1
But how do i rewrite this using htaccess properly? What i've got so far:
RewriteEngine On
RewriteRule ^centrale/(.*)$ /index.php?module=centrale ????? $1
Notice that the DIO0 parameter is not always the only one, so the query string must be completly passed trough. Thanks in advance for helping me out or setting me in the right direction.
Edit: the htaccess file is located here: http://example.com/folder/
Try this :
RewriteEngine on
RewriteBase /folder/
RewriteRule ^centrale/$ index.php?module=centrale [L,QSA]
the [QSA] flag (Query String Append) will add the rest of the parameters automatically

mod_rewrite remove query string on top of a rewrite rule

I have the following rewrite rule:
RewriteRule ^(.*)-task-(.*)\.html$ /index.php/task/name/$2\-task\-$1 [L]
When I tried to open:
/heru-task-number-1.html
It is working fine. HOwever, when there is a query string appended to it:
/heru-task-number-1.html?whatever=value
It is actually not calling the correct rewrite. Thus, I wonder how can I make sure so that both:
/heru-task-number-1.html
AND
/heru-task-number-1.html?whatever=value
are actually calling the same thing that is:
/index.php/task/name/$2\-task\-$1
I have tried to do this but to no avail.
RewriteRule ^(.*)-task-(.*)\.html\?(.*)$ /index.php/task/name/$2\-task\-$1 [L]
Thank you for your help or feedback on this.
This is fixed by inserting the following code at the top of htaccess:
RewriteCond %{QUERY_STRING} (^|&)fb_comment_id=
RewriteRule ^(.*)$ /$1? [L,R=301]
basically, what it does is that it will remove any extra query string that has fb_comment_id and redirect 301 to the one without query string.
Thank you #oddant and #Gerben for helping out!

Trying to create a rewrite rule in .htaccess

I have a url that looks like this
www.myurl.com/page/blog
which works fine with my current rewrite rule. But when I try to append append additional query stings to it it doesn't work.
www.myurl.com/page/blog?group=2
Is there something I could add to my rewrite rule that will make it catch all additional query strings?
This is my current rule:
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
You need to add the [QSA] flag to pass through the original query string params i.e.
RewriteRule ^page/([^/.]+)/?$ index.php?page=$1 [L,QSA]

.htaccess rewrite rule is discarding my querystring

My URL is like
http://172.16.3.97:82/shop/t-shirts/full-zip-sweatshirt?options=367:731,368:737,369:741&custom_inscription=test
and I wrote rewrite rule like
RewriteRule ^shop/t-shirts/([a-zA-Z0-9\-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2
I got only full-zip-sweatshirt in $_GET but I am not able to get other parameters.
How should I write Rule in .htaccess ?
Try to change your rewrite rule for this :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2 **[L,QSA]**
The flag "QSA" add the original query string to your query
Or maybe this one should also help :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2&%{QUERY_STRING}

How can I forward a query string using htaccess?

I am using this, at present, to rewrite URLS:
RewriteEngine on
RewriteRule ^([^/?\.]+)$ /page.php?name=$1 [NC]
So mysite.com/home gets rewritten to mysite.com/page.php?name=home
How can I make it also rewrite mysite.com/home?param=value to mysite.com/page.php?name=home&param=value? Ideally, I'd like this to work for any name/value querystring pairs.
Am I missing something obvious?
Check out the "capturing variables" section at http://corz.org/serv/tricks/htaccess2.php
It says that if you add [QSA] to the end of the rewrite rule, it should pass variables through the rewrite.
This made it work:
RewriteEngine on
RewriteRule ^([^/?\.]+)$ /page.php?name=$1&%{QUERY_STRING} [NC]

Resources