Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule with parameters

         

liza28

9:48 am on Dec 13, 2010 (gmt 0)

10+ Year Member



hi!

I have this URL

[website.com...] which I want to redirect to [website.com...]

how should I do that?

Basically I have par=new1|new2|new3|new4 that would like to be redirected to [website.com...]

Any help from you will be very much appreciated. Thanks!

g1smd

1:11 pm on Dec 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's two lines of code.

There's more than 10 000 previous threads with code snippets with clues to how to do this.

What have you tried so far, and what were the results? "Didn't work" is a non-useful answer.

liza28

1:25 pm on Dec 13, 2010 (gmt 0)

10+ Year Member



Hi!Thank you for jumping in. I actually tried this

RewriteCond %{QUERY_STRING} ^.*par=new1$
RewriteRule ^folder/New.jsp $ [website.com...] ? [R=301,L]

not successful.

jdMorgan

2:12 pm on Dec 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There should be no space between the URL-path pattern and its end-anchor, or preceding the "?" on the substitution URL.

# Externally redirect to remove query string from /folder/New.jsp?<optional_parms&>par=new1<&optional_parms>
RewriteCond %{QUERY_STRING} ^([^&]*&)*par=new1(&.*)?$
RewriteRule ^folder/New\.jsp$ https://www.website.com/folder/New.jsp? [R=301,L]

Also, escape all literal periods in regex patterns, and use "soft anchors" to unambiguously match your query string, even if preceded/surrounded/followed by any other name/value pairs.

This assumes that this code is going into www.website.com/.htaccess and that you already have other working rewriterules in that file. If not, you need to say so. Also, "Not successful" is not a very useful error report. To resolve this problem quickly, please provide detail on your test method, expected results, actual results, and differences between the expected and actual results.

Jim

liza28

3:43 pm on Dec 14, 2010 (gmt 0)

10+ Year Member



hi! Jim. Thanks for your response. The rule worked but in httpd.conf
There's actually a rule in httpd.conf that hindrance that rule to work in .htaccess. You've been helpful. Thanks!