Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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://

share|improve this answer
    
Thanks man. How can I add this to .htaccess? –  Jon Doe Feb 25 '11 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 '11 at 2:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.