[Web4lib] help with an Apache redirect

steven turner Steven.Turner at usm.edu
Mon Oct 12 11:59:48 EDT 2009


Thanks Matt, Thomas and Andrew - those are all great suggestions, and  
thanks Thomas for the reminder about the hexadecimal code - I actually  
see a lot of that and didn't even think about writing a separate  
redirect  - I am going to try all of those suggestions and see what  
works.

S


On Oct 12, 2009, at 9:43 AM, Thomas Dowling wrote:

> On 10/12/2009 09:58 AM, steven turner wrote:
>> Hi All -
>>
>> In Apache, I've been trying to write a redirect to perform a simple
>> regex URL rewrite  using Mod_Redirect and/or Mod_Rewrite on a client
>> request string, but I can't seem to get it to work...
>>
>> I'm simply trying to replace the sub-string "/~"  (that's a backslash
>> and a tilde) with the substring "/legacy" in this example/theoretical
>> URL: "http://www.lib.usm.edu/~spcol/folderName/pageTitlle.php"


---

I'm assuming you want to replace "/~spcol" with "/legacy/spcol". In
that case, you can try:

RewriteRule "^/~([\w\d\W\D]+)" http://www.example.com/legacy/$1

Everything inside the () is captured as variable $1, and then appended
at the end of the URL. \w captures words, \d captures digits; their
capital variations capture not words and not digits, respectively.
Basically this says "capture anything that comes after a tilde, and
write the URL with that."

Hope that helps.
-Andrew


Hi Steve,

Try this:
RedirectMatch 301 /~(.*) http://www.yourdomain.com/legacy/$1

Whatever follows the tilde in the regex will be repeated at $1

Matt
>>
>
>
> It's a shot in the dark, but my first hunch would be to backslash- 
> escape it,
> since the tilde has special meaning in regexp-speak.
>
>  RedirectMatch /\~(.*) http://ourserver.edu/legacy$1
>
> And just to cover the few referers that hex-escape tildes in URLs:
>
>  RedirectMatch /%7E(.*) http://ourserver.edu/legacy$1
>
>
> -- 
> Thomas Dowling
> tdowling at ohiolink.edu
>

-----------------------------------------
Steven Turner
Library Web Services Manager
Associate Professor
The University of Southern Mississippi
Cook Library
-----------------------------------------
email: steven.turner at usm.edu
phone: 601.266.4066
-----------------------------------------







More information about the Web4lib mailing list