Solved

How can I avoid URL encoding from htaccess 301 redirect?

Posted on 2011-02-25
8
1,825 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 83

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

920 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

15 Experts available now in Live!

Get 1:1 Help Now