?
Solved

How can I avoid URL encoding from htaccess 301 redirect?

Posted on 2011-02-25
8
Medium Priority
?
1,962 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:

http://www.site.com/index.php?iframe~iframe+url~http://www.site.com/plan.php?s=42&l=126

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

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]

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

http://www.site.com/index.php?iframe~iframe+url~http://www.site.com/plan.php%3fs=42&l=126

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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 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
 
LVL 84

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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