Sunday, March 20, 2011

mod_rewrite redirect to URL with propietary protocol

I'm using Apache 2.2 with mod_rewrite.

Is there a way to force mod_rewrite to rewrite the entire URL, including protocol? I know it will automatically rewrite the whole URL if the redirect contains http:// at the beginning but I'm trying to redirect to a URL that uses a proprietary protocol: fcp://

When I add it in as the redirect it just redirects to the URL of my server with the rewrite appended like so:

http://www.example.com/fcp://@mailstaff....

Can I configure the module to treat fcp:// as a full URL so I don't run in to this?

UPDATE: Here is the code I am using:

RewriteCond ${externals:$2|Unknown} !Unknown
RewriteRule ^(internal|external)/(.*)/? ${externals:$2} [R=301,NE,L,NS]

Inside the externals RewriteMap, I have a line like this:

firstclass-email     fcp://@mailstaff.example.com/

When I go to trigger the RewriteRule by going to:

http://example.com/internal/firstclass-email

It will incorrectly redirect me to here:

http://example.com/fcp://@mailstaff.example.com/

If I change the protocol part from fcp:// to http://, Apache will realize it's an absolute URL and work correctly. I want Apache to recognize fcp:// should also be absolute.

From stackoverflow
  • Have you tried this?

    RewriteRule ^/yourUrl$ fcp://otherUrl [RL]
    
    Gumbo : That’s rather a question than an answer. But anyways, have you tried that on your own?
    Taylor Leese : Haven't tried it, but it's my suggestion of what to try. Do you see something wrong with it?
    Taylor Leese : I posed it as a question/answer because he didn't list what RewriteRule's he was currently using.
    sirlancelot : Yes, see the second half of my question for the result. It just adds the substitution part to the server's domain name.
    Taylor Leese : Please post the actual RewriteRule that you are using.
    sirlancelot : I updated with the rules I'm using.
  • Apache can only handle the most common URL schemes like http, https, ftp, mailto, etc. Custom URL schemes are not recognized as such but handled as a URL path.

    See the is_absolute_uri function in the source code of mod_rewrite.c for details on what schemes are supported.

    sirlancelot : That's what I feared :( Is there any way to change this in userland?
    Gumbo : Try to use a script that handles the redirect instead of Apache.

0 comments:

Post a Comment