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
Solved

How can I avoid URL encoding from htaccess 301 redirect?

Posted on 2011-02-25
8
1,860 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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
 
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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