簡體   English   中英

.htaccess將sub.DomainA重定向到DomainB / Subdir而不更改URL

[英].htaccess Redirect sub.DomainA to DomainB/Subdir Without Changing URL

我已經徹底搜索了網絡以獲得答案,沒有任何運氣。

我正在嘗試編寫一個執行以下操作的htaccess重定向:

重定向:

subdomain.DomainA.com

至:

DomainB.com/subdir/

但是不更改地址欄中顯示的URL,並保持直接鏈接訪問subdomain.DomainA.com

所以subdomain.DomainA.com/link/1000成為DomainB.com/subdir/link/1000

這是我去過的最接近的,但我還不能指出它。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.DomainA.com$
RewriteRule ^(.*)$ http://DomainB.com%{REQUEST_URI} [P]

我也試過RewriteRule ^(.*)$ http://DomainB.com/subdir%{REQUEST_URI} [P] ,但由於某種原因這會返回subdomain.DomainA.com/subdir :(

任何幫助將不勝感激!

如上所述,當你使用[P]時,你實際上是在調用mod_proxy。 您必須先使其工作,然后才能在重寫規則中使用它。 實際上,您是否為要嘗試訪問的主機啟用了Proxy?

http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxy

<Proxy http://DomainB.com>
   Require all granted
</Proxy>

您可以增加LogLevel(和/或)RewriteLogLevel來幫助調試它無法正常工作的原因(我不記得代理拒絕是在重寫日志中還是只是普通的錯誤日志)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM