0

我昨天问了一个关于这个的问题,但我的 httpd.conf 仍然有问题。

我想要发生的是这样的:

  • 用户请求http://www.mysite.com/mysite.com等。然后将它们重定向到https://www.mysite.com/shop/

  • 我还想确保/shop子目录下的任何请求也被重写为 HTTPS,即使用户在其中键入的http://www.mysite.com/shop/help/内容将被重写为https://www.mysite.com/shop/help/

这是我现在的配置,它不起作用。

Listen *:443 https
Listen *:80 http

<VirtualHost *:80>
    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(shop/.*)$ https://%{HTTP_HOST}/shop/$1 [NC,R=301]
    RewriteRule ^/$ https://%{HTTP_HOST}/shop/ [NC,R=301,L]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine On
    SSLAppName QIBM_HTTP_SERVER_ZENDSVR
    SetEnv HTTPS_PORT 443
    RewriteEngine on
    RewriteRule ^/$ https://%{HTTP_HOST}/shop/ [NC,R=301]
</VirtualHost>
4

1 回答 1

1

首先,确保 mod_rewrite 在您的服务器收到请求时启动。例如,将所有请求从您的 HTTP 主机重定向到您的 HTTPS 服务器

<VirtualHost *:80>
    RewriteEngine on
    RewriteRule .* https://%{HTTP_HOST}/shop/ [R,L]
</VirtualHost>

然后尝试

<VirtualHost *:80>
    RewriteEngine on
    RewriteRule ^/?shop/(.*) https://%{HTTP_HOST}/shop/$1 [NC,R=301,L]
    RewriteRule ^/?$ https://%{HTTP_HOST}/shop/ [R=301,L]

    # other directives
</VirtualHost>

<VirtualHost *:443>
    RewriteEngine on
    RewriteRule ^/?$ https://%{HTTP_HOST}/shop/ [R=301,L]

    # other directives
</VirtualHost>
于 2012-06-06T07:51:30.913 回答