首页 文章

mod_rewrite使用propietary协议重定向到URL

提问于
浏览
2

我正在使用带有mod_rewrite的Apache 2.2 .

有没有办法强制mod_rewrite重写整个URL,包括协议?我知道如果重定向在开头包含 http:// ,它会自动重写整个URL,但我正在尝试重定向到使用专有协议的URL: fcp://

当我将其作为重定向添加时,它只是重定向到我的服务器的URL,并附加重写,如下所示:

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

我是否可以将模块配置为将 fcp:// 视为完整URL,以便我不参与此操作?

UPDATE: 这是我正在使用的代码:

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

externals RewriteMap中,我有一个这样的行:

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

当我通过转到:触发RewriteRule时:

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

它会错误地将我重定向到这里:

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

如果我将协议部分从 fcp:// 更改为 http:// ,Apache将意识到它是一个绝对URL并且正常工作 . 我希望Apache能够识别 fcp:// 也应该是绝对的 .

4 回答

  • 0

    您可以使用 RedirectMatch 而不是 RewriteRule .

    检查How to handle mod-rewrite with a custom url scheme?以获取解释......

  • 0

    你试过这个吗?

    RewriteRule ^/yourUrl$ fcp://otherUrl [RL]
    
  • 2

    相当古老的问题 - 但我可以回答 . 我有同样的问题 . 这可以通过两个重定向来解决 .

    Redirect /restore1 fcp://example.com/restore
    
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile.....
    RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|.....
    RewriteRule ^restore/(.*)$ http://example.com/restore1/$1
    
  • 2

    Apache只能处理最常见的URL方案,如 httphttpsftpmailto 等 . 自定义URL方案不会被识别,但作为URL路径处理 .

    有关支持哪些方案的详细信息,请参阅source code of mod_rewrite.c中的 is_absolute_uri 函数 .

相关问题