2009-09-04 73 views
2

我使用Apache 2.2與mod_rewrite。mod_rewrite重定向到URL與propietary協議

有沒有辦法強制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/ 

當我去了觸發重寫規則去:

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

它會increcrec TLY重定向我在這裏:

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

如果我更改協議的一部分從fcp://http://,Apache會意識到這是一個絕對的URL和正常工作。我希望Apache認識到fcp://也應該是絕對的。

回答

2

阿帕奇只能處理最常見的URL方案,如:httphttpsftpmailto等自定義URL方案無法識別本身,而是作爲一個URL路徑處理。

有關支持哪些方案的詳細信息,請參閱source code of mod_rewrite.c中的is_absolute_uri函數。

+1

這就是我所擔心的:(有什麼方法可以在用戶空間中更改它嗎 – matpie 2009-09-04 21:01:33

+2

嘗試使用處理重定向而不是Apache的腳本 – Gumbo 2009-09-04 21:15:23

+0

「Apache只能處理...」 - 嚴格來說,它是* mod_rewrite *只能處理最常見的URL方案,其他模塊(如mod_alias:'Redirect' /'RedirectMatch')似乎是「處理」它們。 – DocRoot 2017-08-08 20:47:17

0

你試過嗎?

RewriteRule ^/yourUrl$ fcp://otherUrl [RL] 
+0

這不是回答的問題。但無論如何,你有沒有嘗試過嗎? – Gumbo 2009-09-04 18:50:15

+0

還沒有嘗試過,但這是我的建議。你看到有什麼問題嗎? – 2009-09-04 18:57:22

+0

我把它作爲一個問題/答案提出,因爲他沒有列出他目前使用的RewriteRule。 – 2009-09-04 19:00:06

0

相當古老的問題 - 但我可以回答。我有同樣的問題。這可以通過兩個重定向來解決。

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