Rewrite Rule to Work on HTTP and HTTPS

2019-01-26 09:22发布

问题:

I have this simple rewrite rule and it works properly under http:

RewriteCond %{HTTP_HOST} ^www\.siku-siku\.com$
RewriteRule ^/work/all.html  /portfolio/ [L,R=301]

However, the rule doesn't take into effect when I was on https. I modified the rule set to the following but to no avail.

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.siku-siku\.com$
RewriteRule ^/work/all.html  /portfolio/ [L,R=301]

How can I make that rule to work both on http and https? Please let me know if I need to provide more information.

回答1:

Apache uses a different vhost for ssl configuration:

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.siku-siku\.com$
  RewriteRule ^/work/all.html  /portfolio/ [L,R=301]
  ...
  </VirtualHost>
</IfModule>

This link has an example for configuring Apache with SSL on Debian, but should be easy to extrapolate to whichever platform you are on http://www.debian-administration.org/articles/349