簡體   English   中英

使用.htaccess處理子域和https

[英]Handling subdomains and https with .htaccess

在下面的.htaccess示例中,如果有人輸入如下網址:

http://mysite.com/ricks-motorcycles

...它將自動從x.com的位於public_html的名為“ ricks-motorcycles”的子目錄中加載頁面。 此技術稱為代理吞吐量

RewriteEngine On
RewriteRule ^ricks-motorcycles/(.*)$  http://x.com/ricks-motorcycles/$1 [P,L]

很好,但是我該如何處理另外兩種情況:

(1)有人想要https而不是http。

(2)有人想要...

http#// ricks-motorcycles.mysite.com/

...代替...

http#// mysite.com/ricks-motorcycles/

(在上面用#切換#,因為StackOverflow阻止了我發布消息。)

您可以使用RewriteCond來限定您的重寫:

RewriteEngine On

RewriteCond %{HTTPS} =on
RewriteRule ^ricks-motorcycles/(.*)$ https://example.com/ricks-motorcycles/$1 [P,L]

RewriteCond %{HTTP_HOST} =ricks-motorcycles.mysite.com
RewriteRule ^(.*)$ http://example.com/ricks-motorcycles/$1 [P,L]

有關更多信息,請參見mod_rewrite文檔

暫無
暫無

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

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