Apache 使用.htaccess处理子域和https

Apache 使用.htaccess处理子域和https,apache,.htaccess,ssl,https,subdomain,Apache,.htaccess,Ssl,Https,Subdomain,在下面的.htaccess示例中,如果有人键入如下URL …它将自动从x.com的子目录加载名为“ricks Motorkes”的公共html下的页面。这种技术称为代理吞吐量 这很好,但我如何处理其他两种情况: (1) 有人想要https而不是http (2) 有人想要 http#//ricks-motorkes.mysite.com/ …而不是 http#//mysite.com/ricks-motorkes/ (切换为:以上,因为StackOverflow阻止我发布。)您可以使用重写条件来

在下面的.htaccess示例中,如果有人键入如下URL

…它将自动从x.com的子目录加载名为“ricks Motorkes”的公共html下的页面。这种技术称为代理吞吐量

这很好,但我如何处理其他两种情况:

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

(2) 有人想要

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

…而不是

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


(切换为:以上,因为StackOverflow阻止我发布。)

您可以使用
重写条件来限定您的重写:

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]

有关更多信息,请参阅。

谢谢,它离我很近,足以让我出发。
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]