Forum Moderators: phranque

Message Too Old, No Replies

Need Help on rewrite Rule Please

         

coolvibh

1:27 pm on May 21, 2010 (gmt 0)

10+ Year Member



I have a link lets call it xyz.
My rewriteRule is

RewriteRule ^/clickout/sd3/(.+)$ http://nl.example.com/elsevier/elsevier-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1

where $1 one is coming from the requested page which will be a query string

but when i click on my link xyz query string is not appened ..
$1= ?issn=1234&volume=7;


Please help me out friends.

[edited by: jdMorgan at 2:18 pm (utc) on May 21, 2010]
[edit reason] example.com [/edit]

jdMorgan

2:31 pm on May 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The form of your code implies that it is located in httpd.conf or some other server config file, and further, that it is not contained within a <Directory> section in that config file. The code won't work in .htaccess or in a <Directory> section in a server config file.

So in order to match your code, the requested URL-path would have to be
/clickout/sd3/xyz
if the desired result is a redirect to http://nl.example.com/elsevier/elsevier-com/s?sd3&ns_type=clickout&ns_url=http://www.example2.com/xyz

If the /clickout/sd3/xyx URL that you receive from the client also has a query string, and you wish to preserrve that query string through this redirect, then you need to use the [QSA] flag (Query String Append) on the rule. Further, unless you have a known and very good reason not to do so, your rule should also use an [L] flag, making the flag value [QSA,L].

If the value to be placed in $1 is a query string appended to you "xyz" link, then you must use a RewriteCond to examine %{QUERY_STRING}, and back-reference the value from there.

The description of your requirements regarding input and output URLs is lacking in detail and examples, so that's the best I can come up with.

Jim

[edited by: jdMorgan at 3:49 pm (utc) on May 21, 2010]

coolvibh

3:28 pm on May 21, 2010 (gmt 0)

10+ Year Member



Hi Jim,

Actually this entry is included in my server.conf file which has a refrence in httpd.conf file .

jdMorgan

3:48 pm on May 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Actually this entry is included in my server.conf file which has a refrence in httpd.conf file.

Is it contained in a <Directory> section? If so, how is that section currently specified?

The description of your requirements regarding input and output URLs is lacking in detail and examples, so that's the best I can come up with.


No further progress is possible without more information. Replacing your real domain with "example.com," what are you required input and output URLs?

Answers to all of these questions are needed.

Jim

coolvibh

9:54 am on May 24, 2010 (gmt 0)

10+ Year Member



Hi Jim....

I have httpd.conf file in which i have a entry

Alias /icons/ "C:/IBM HTTP Server/icons/"
include conf/cwsdev-stg.conf

<Directory "C:/IBM HTTP Server/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

where cws-dev.conf file contains rewriterule entry

Now for rewrite rule entry is define as

RewriteRule ^/clickout/sd3/(.+)$ http://nl.example.com/elsevier/elsevier-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1

final output should come as
http://www.sciencedirect.com/?issn=4321&volume7

but for me with this entry query strind is not getting appended....if u need more help i can provide..As it's urgent can please help me out


Thanks
regards
Vaibhav

[edited by: jdMorgan at 12:28 pm (utc) on May 24, 2010]
[edit reason] example.com [/edit]

coolvibh

10:05 am on May 24, 2010 (gmt 0)

10+ Year Member



clickout/sd3/YYY should be redirected to:
http://nl.example.com/exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/YYY (which will eventually end up at http://www.sciencedirect.com/YYY).


What I observe is that the link http://stg.cwsactx.exampl2.com/clickout/sd3/science/publication?issn=15674231&volume=7 ends up at http://www.sciencedirect/science/publication. The part of the URL starting with the question mark is lost.

[edited by: jdMorgan at 1:10 pm (utc) on May 24, 2010]
[edit reason] examplified and de-linked. [/edit]

jdMorgan

1:04 pm on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I already provided information on preserving the input query string earlier in this thread, but here's an example:

RewriteRule ^/clickout/sd3/(.+)$ http://nl.example.com/exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1 [b][R,QSA,L][/b]

Note the highlighted flags on the rule.

I am not sure what the server will make of the new URL, which will actually have two "nested" query strings appended to it. But give this a try. If it does not work, then it will be necessary to encode or to replace the second "?" with some other character, and then modify your exit-tracking script to restore that "?" before the request leaves your server.

The corrected rule should work like this:
http://www.example.com/clickout/sd3/xyz?abc --302-redirect--> http://nl.example.com/exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/xyz?abc

If "nl-example.com" is your own server, then the external redirect invoked by this mod_rewrite code should not be necessary. Assuming that the request for "/s" invokes your exit-tracking script, you could speed things up by using an internal rewrite like this instead of an external redirect to your script:

RewriteRule ^/clickout/sd3/(.+)$ /exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1 [QSA,L]

Using this internal rewrite also avoids exposing your exit-tracking script URL to visitors and to search engines.

You can further speed up your server by disabling MultiViews (content-negotiation) if they are not required for the proper operation of your site.

Please note that for many reasons, we do not allow posting of URLs here, except for "well-known" URLs. I have substituted "example.com" and "exampl2/exampl2-com" in the code and examples above to comply with our terms of service.

Jim

coolvibh

1:36 pm on May 24, 2010 (gmt 0)

10+ Year Member



hi Jim,

i have done what you told but again now my final url generating is
http://www.sciencedirect.com/science/publication&issn=15674231&volume=7

instead of
http://www.sciencedirect.com/science/publication/?issn=15674231&volume=7

Can you help me on this and
""nl-example.com" is third party server so we can't change the configration...

Hope You can give me further solution

regards
Vaibhav

[edited by: jdMorgan at 4:02 pm (utc) on May 24, 2010]
[edit reason] de-linked [/edit]

coolvibh

1:45 pm on May 24, 2010 (gmt 0)

10+ Year Member



Href value on moving mouse over the link is coming out to be
http://localhost/clickout/sd3/science/publication?issn=1234&volume=9

[edited by: jdMorgan at 4:01 pm (utc) on May 24, 2010]
[edit reason] De-linked [/edit]

jdMorgan

4:24 pm on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, as I feared, it's because you're trying to put two "?" characters into one query string... You will have to escape the second one, and (possibly) un-escape it (using urldecode) in your redirect script.

This *might* work as a way to do it with a single rule (I did not test this).

RewriteCond \%3F%{QUERY_STRING} ^((\%3F.+)|\%3F)$
RewriteRule ^/clickout/sd3/(.+)$ http://nl.example.com/exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1%2 [NE,R=302,L]

This method avoids adding the (encoded) trailing "?" if the original query string was blank.

It will only work if your redirect script can accept an encoded "?" for the second "?" in the query string passed into it.

If this doesn't work, then you will probably need to modify your script to accept two parameters -- the URL that you want to redirect to, and the query string to be passed to that URL -- as separate items. The script can then re-assemble the target URL-plus-query string and generate the required redirect.

You're basically struggling with the requirements of the HTTP protocol here, and not with any server or coding-specific problems; Webmasters *are not* free to put any characters they like into URLs and query strings, and must comply with the protocol requirements. In this case, trying to put two "?" characters into one query string is the problem.

Jim

coolvibh

9:12 am on May 25, 2010 (gmt 0)

10+ Year Member



Thanks Buddy...It's working properly now.

Yamuna

5:52 am on Jun 17, 2010 (gmt 0)

10+ Year Member



Hi

I have a link http://www.xyz.com/clickout/sd3

and it is getting redirected to the intended url properly with the below specified rewrite rule.

RewriteCond \%3F%{QUERY_STRING} ^((\%3F.+)|\%3F)$
RewriteRule ^/clickout/sd3/(.+)$ http://nl.example.com/exampl2/exampl2-com/s?sd3&ns_type=clickout&ns_url=http://www.sciencedirect.com/$1%2 [NE,R=302,L]

Now the issue is, if I provide the link as http://www.xyz.com/clickout/sd3, redirection works fine and if www is removed from the url http://xyz.com/clickout/sd3, redirection is not happening.

Whereas all the other pages in the domain works without www.

Can some one help me out to identify the issue and resolve it.

Thanks & Regards
Yamuna

[edited by: jdMorgan at 2:28 pm (utc) on Jun 17, 2010]
[edit reason] De-linked [/edit]

jdMorgan

2:34 pm on Jun 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This would indicate that some other rule is interfering with your code, because the code you posted does not care about which hostname is requested.

Look at all of the code in your server config files, and be sure that any rule which examines %{HTTP_HOST} is correct, and that it does not accidentally clear the requested query string or make other changes which would cause the pattern in this rule to not match.

Also, be aware that the RewriteCond pattern in your rule is 'weak' and that it will simply take *any* query string parameter(s) following the first one, and append it/them to the new query string. You might consider making this pattern more specific -if possible- by matching specific query string parameter names in the requested query string. This would avoid potential for abuse of your site.

Jim