使用.htaccess处理子域和https

时间:2009-06-28 07:29:18

标签: apache .htaccess ssl https subdomain

在下面的.htaccess示例中,如果有人输入如下所示的网址...

http://mysite.com/ricks-motorcycles

...它会自动从名为“ricks-motorcycles”的public_html下的x.com子目录中加载页面。此技术称为代理吞吐量

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 /

(切换#with:上面因为StackOverflow阻止我发布。)

1 个答案:

答案 0 :(得分:1)

您可以使用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 documentation