1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

mod_rewrite force https on certain domain/hosts

Discussion in 'Apache' started by theroot, Jun 27, 2012.

  1. #1
    So I'm trying to create a mod_rewrite rule that will force only certain host/domains to rewrite everything from http:// to https://.

    I basically have an internal site and an external site. Internal site needs to be on port 80 or 443 whatever they originally went to the site as. However anything coming through on the external site on port 80 / http needs to be rewritten to 443 / https.

    Everyway I try I can't seem to get it to work. I can get it to rewrite everything to https regardless of host. Rewrite only the external site to https and any attempt to go to the internal address results in a apache error. I guess I cant figure out the way to RewriteCond include these addreses and exclude those.

    I've tried numerous suggestions and configs, i think this was my last non working setup:


    
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^external\.mysite\.com
    RewriteCond %{HTTP_HOST} !^internalsite
    RewriteCond %{HTTP_HOST} !^internalsite\.mysite\.local
    RewriteRule ^(.*)$ https://external.mysite.com/$1 [R,L]
    
    Code (markup):
    I'm sure this is a pretty simple answer for anyone out there. I haven't had a whole lot of experiece with modrewrites other then simple redirects and redirecting everythnig for a site directory to https.

    Thanks!
     
    theroot, Jun 27, 2012 IP
  2. bestemployer

    bestemployer Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    What exactly do you mean by excluding internal sites? Try appending this:
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^internalsite
    RewriteCond %{HTTP_HOST} ^internalsite\.mysite\.local
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
     
    bestemployer, Aug 17, 2012 IP