The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array with special Characters donaldfung UNIX for Dummies Questions & Answers 1 06-08-2008 09:18 AM
Grep with Special Characters Vashj Shell Programming and Scripting 6 11-27-2007 03:51 AM
Put a \ in front of special characters in SED tugger Shell Programming and Scripting 9 10-17-2007 04:12 AM
special characters nawnaw UNIX for Dummies Questions & Answers 2 05-18-2004 12:17 PM
awk/sed with special characters apalex Shell Programming and Scripting 5 05-06-2002 01:40 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2008
Registered User
 

Join Date: Oct 2007
Posts: 17
apache encode special characters in URL

Hi all,

How can I enable encoding of special characters present in URL?

eg

If the URL is

http://127.0.0.1/test.cgi?param1=test & test co

it shouldbe encoded to

http://127.0.0.1/test.cgi?param1=test%20%26%20test%20co

Thanks and Reagards,
uttam hoode
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Cool Does this help?

Code:
> inval="http://127.0.0.1/test.cgi?param1=test & test co"
> echo "$inval"
http://127.0.0.1/test.cgi?param1=test & test co
> outval=$(echo "$inval" | sed "s/ /%20/g" | sed "s/&/%26/g")
> echo "$outval"
http://127.0.0.1/test.cgi?param1=test%20%26%20test%20co
Reply With Quote
  #3  
Old 07-23-2008
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,477
Well, there are far more special characters that need escaping instead of just a space or ampersand. In what way would you like to do the URL escape? Can you explain further your situation?

By the way, if the URLs are generated by dynamic scripting such as PHP or Perl, parameter escaping is usually handlded by default or there is API for you to do the needed encoding, so you typically do not need to worry about escaping at all.

For Perl, if you don't mind installing CPAN modules, the easiest and most reliable way is to use the URI module (this is my favourite). It can parse, and create many kinds of properly formatted URLs. This is an example:

URI::QueryParam - Additional query methods for URIs - search.cpan.org
Reply With Quote
  #4  
Old 07-24-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Or do you mean something like mod_rewrite's escape function? See e.g. Mod_Rewrite Forums :: Index
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0