繁体   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