Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite Rule to Work on HTTP and HTTPS

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.

like image 934
moey Avatar asked Jan 06 '12 15:01

moey


People also ask

What is a URL Rewrite rule?

A rewrite rule defines the logic of what to compare or match the request URL with, and what to do if the comparison is successful. Rewrite rules consists of the following parts: Pattern – The rule pattern is used to specify either the regular expression or a wildcard pattern that is used to match URL strings.


1 Answers

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

like image 143
speeves Avatar answered Oct 12 '22 15:10

speeves