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

不问归期 提交于 2020-01-01 19:01:13

问题


So here's my problem : I'm trying to do a redirection on a webpage with the htaccess file. This redirection will be towards a custom URL (i.e not something ike "http://..." but something like "myurl://...).

For now, I'm trying this on a little local apache server, in which I have a index.html page, a "test" directory and in this directory a .htaccess file and a test.html file.

Here's what's inside the .htaccess file :

Options +FollowSymLinks
RewriteEngine   On
RewriteBase /
RewriteRule     ^(.*)$ myurl://test$1 [R=302]

I think the problem probably comes from here, as I'm totally new at this and this is the first time I try to write into a .htaccess file. So, if this is not the proper way to do this, what is the proper way to do this then ?

Thanks to anyone who can help


回答1:


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



回答2:


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}.



来源:https://stackoverflow.com/questions/24136175/how-to-handle-mod-rewrite-with-a-custom-url-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!