Solved

How can I avoid URL encoding from htaccess 301 redirect?

Posted on 2011-02-25
8
1,799 Views
Last Modified: 2012-05-11
I'm using an htaccess page for 301 redirects, but the redirected URL is being sent to browsers with some URL encoding. I'm hoping to find a way to avoid the encoding.

The URL I'm redirecting to looks something like this:


The line of code on my htaccess page looks like this:


The problem is that the 2nd '?' character is getting sent to the browser URL encoded, so the resulting URL looks like this:


Is there a way to change the code on my htaccess page so that the URL will be sent exactly as is, without getting URL encoded?

Thanks.
0
Comment
Question by:Jonathan Greenberg
  • 4
  • 3
8 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34985418
First try quoting it with a backslash and see if that has any effect:

RewriteRule ^this\.page$ http://www.site.com/index.php?iframe~iframe+url~http://www.site.com/plan.php\?s=42&l=126 [R=301,L,NC]

Open in new window

0
 

Author Comment

by:Jonathan Greenberg
ID: 34985435
No, no effect. Great idea, though.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34985457
Here's why you're getting burned.   Haven't found the workaround yet but looking.  Interesting.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Down the page inside the RewriteRule section:

"One more note: You can even create URLs in the substitution string containing a query string part. Just use a question mark inside the substitution string to indicate that the following stuff should be re-injected into the QUERY_STRING. When you want to erase an existing query string, end the substitution string with just the question mark."
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 34985466
Here it is, I think:

•'noescape|NE' (no URI escaping of output)
This flag keeps mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from being done. This allows percent symbols to appear in the output, as in
    RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
   
which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'. Notice: The noescape flag is only available with Apache 1.3.20 and later versions.

RewriteRule ^this\.page$ http://www.site.com/index.php?iframe~iframe+url~http://www.site.com/plan.php?s=42&l=126 [R=301,L,NC,NE]

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 34985468
It's going to a PHP page, URLdecode it.  http://us.php.net/manual/en/function.urldecode.php  that page does say that "$_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results. "

Does it work on that page?  Do a print_r ($_GET); to see if you really have a problem.
0
 

Author Comment

by:Jonathan Greenberg
ID: 34985567
Yeah, I think you've found what the problem is. I hope there's a solution.
0
 

Author Comment

by:Jonathan Greenberg
ID: 34985572
Sorry, my last comment was meant for post at ID 34985457. Please ignore it.
0
 

Author Comment

by:Jonathan Greenberg
ID: 34985600
sjklein42: thanks, that does the trick! Exactly what I was hoping for!

DaveBaldwin, thank you, too, for your input.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now