在下面的.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 documentation

07-24 09:54