How to handle mod-rewrite with a custom url scheme? How to handle mod-rewrite with a custom url scheme? apache apache

How to handle mod-rewrite with a custom url scheme?


The issue is related to the RewriteRule itself that checks the url scheme. From the source code mod_rewrite.c it reads only a subset of schemes:

Protocols Recognized by Mod_Rewrite

  • ajp:// - Apache JServ Protocol
  • balancer:// - Apache Load Balancer
  • fcgi://
  • ftp:// - File Transfer Protocol
  • gopher:// - Gopher (protocol)
  • http:// - Hypertext Transfer Protocol
  • https:// - Hypertext Transfer Protocol Secure
  • ldap:// - Lightweight Directory Access Protocol
  • mailto: - The mailto URI scheme
  • news: - News Protocol
  • nntp:// - Network News Transfer Protocol
  • scgi://
  • ws://
  • wws://

Indeed you can use RedirectMatch that doesn't check the protocol as follows:

RedirectMatch /(.*) myurl://$1


Perhaps I'm missing something but the prefix of the URL is the protocol. The client browsing to the url has an application bound to this protocol. HTTP(S) = Browser, MAGNET = torrent client, MAILTO = Email client, etc..

So if your client is configured to actually use that kind of url you will contact your server either in http or https.. so I'm guessing you can't check on protocol.. ?

If apache is accepting your request I guess you can check the entire url using %{SCRIPT_URI}.