0

I'm trying to force a specific URL to use HTTPS, but the problem is that all the links in that page would point to HTTPS of other pages as well.

So, I was thinking about updating my virual host file like this.

<VirtualHost *:80>
    #Rewrite urls under /foo/bar/* to use HTTPS://domain/foo/bar/*
    RewriteEngine on
    RewriteRule ^/foo/bar/(.*) https://domain/foo/bar/$1
</VirtualHost>

<VirtualHost *:443>
    #Rewrite all urls except /foo/bar/* to use HTTP://domain/*  
</VirtualHost>

Any suggestions on how I can implement this?

1 Answer 1

0

You should add the [R,L] flags to the rule. L may be redundant since it is the only rule, but if you add other rules later, the L keeps it from running any more rules if this rule handles the request. R makes it a redirection, so the client is actually sent a redirection command to the https:// site.

For the :443 virtualhost, you'll need to use RewriteCond to exclude cases where the path is /foo/bar/*

RewriteCond %{REQUEST_URI} !^/foo/bar/
RewriteRule ^/(.*)$ http://domain/$1 [R,L]

This basically says if the REQUEST_URI does NOT begin with /foo/bar/, then redirect to http://

2
  • Thanks man. How can I add this to .htaccess?
    – Jon Doe
    Feb 25, 2011 at 1:56
  • Since there's no <VirtualHost *:443> I tried adding RewriteCond %{HTTPS} =on to the existing condition but no luck.
    – Jon Doe
    Feb 25, 2011 at 2:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .