Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite for query string

not sure of rewrite

         

mercsha

6:58 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



I am trying to set up a rewrite rule so that I can add a query string parameter to an existing link. For e.g

RewriteCond %{query_string} ^(.*)$
RewriteCond %{script_name} ^(.*)$
RewriteRule ^/a/b/(.*)$ [example.com...] [QSA,P]

I am not too sure if I need to have the QSA flag. What is desired is if i enter

hello.com/hello1/hello2/hello3?a=1&b=2&c=3 its gets redirected to
[example.com...]

So i get the query string and the file path (/hello1/hello2/hello3 and manually try to append. Where am I going wrong?

gergoe

7:13 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



I dont't really understand your question, but in general if you want to include additonal query string parameters then you can do something like this:

RewriteRule ^(.+\.php)$ $1?newparam=qwe [QSA,L]

This will append the newparam parameter to all requests for any php file on your website. if there was any query string paremeter originally then it will be appended to the end of the query string, and if there wasn't any before, then this will be the first. Some examples:

/index.php => /index.php?newparam=qwe
/index.php?param1=abc => /index.php?param1=abc&newparam=qwe
/index.php?param1=abc&param2=def => /index.php?param1=abc&param2=def&newparam=qwe

mercsha

7:22 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



Hi,
Thanks for the reply. But when i try the following

RewriteRule ^/hello/hello1/(.$)$ [newlink.com...] [QSA,P]

It doesnt seem to add the paramter.

mercsha

7:25 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



I meant

RewriteRule ^/hello/hello1/(.*)$ [newlink.com...] [QSA,P]

jdMorgan

8:19 pm on Jul 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mercsha,

Welcome to WebmasterWorld [webmasterworld.com]!

Do not use a canonical URL -- See gergoe's code above.

Why are you using the Proxy flag?

And if you are putting your code in .htaccess, omit the leading slash from the pattern. From your last post:


RewriteRule ^hello/hello1/(.*)$ /$1?newparam=qwe [QSA,L]

This will rewrite www.example.com/hello/hello/somepage?a=5 to www.example.com/sompage?a=5&newparm=qwe

Apache mod_rewrite documentation [httpd.apache.org]

Jim

mercsha

8:33 pm on Jul 2, 2004 (gmt 0)

10+ Year Member



Hi;

The reason I have the canonical URL is because I am proxying the request to another url, to which is need to add the paramter.