Hi,

I have been pulling my hair out! I have just completed a secure site for my client at http://www.atfundraising.com. Through modifying my .htaccess file in my root I was able to get all traffic to redirect to HTTPS, except for a couple of subdomains. Unfortunately I have one page on the site that has an embedded Google Map on it. Users get error messages because Google Maps can not be accessed via HTTPS unless you are willing to shell out $10000/yr. Mixed content error message. I'm trying to write code to exclude /contact-us/google-map from redirecting to HTTPS, and to add a redirect from HTTPS to HTTP if (and only if) its the google map page. Heres the code thus far:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} !=test.atfundraising.com 
RewriteCond %{HTTP_HOST} !=oldsite.atfundraising.com 
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]


# 
# Redirect non-canonical hostname requests to canonical domain 
RewriteCond %{HTTP_HOST} !=www.atfundraising.com 
RewriteCond %{HTTP_HOST} !=test.atfundraising.com 
RewriteCond %{HTTP_HOST} !=oldsite.atfundraising.com 
RewriteCond %{HTTPS}>s ^(on>(s)|[^>]+>s)$ 
RewriteRule ^(.*)$ http%2://www.atfundraising.com/$1 [R=301,L] 

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^atfundraising\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.atfundraising.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I ahve tried various RewriteCond, and none of them work.

Any help would be GREATLY appreciated!

TIA,

:) David

Comments

WillHall’s picture

Not sure if it will help - but I was able to modify this to suit similar needs on an old project.

http://www.askapache.com/htaccess/http-https-rewriterule-redirect.html

dapperry’s picture

I looked at your link, but did not see any examples for excluding a certain page from https redirection or for redirecting a certain page from https to http. Do you have a code example of what you did?

dapperry’s picture

By chance I came accross: http://drupal.org/node/181233

It helped tremendously. Big thing was to put path in parenthesis (contact-us/google-map). Heres the code for anyone who was as lost as I was!

# Redirect everything non-HTTPS to HTTPS, unless its an include file, belongs to a different subdomain, or is the google-map page
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} !=test.atfundraising.com 
RewriteCond %{HTTP_HOST} !=oldsite.atfundraising.com 
RewriteCond %{REQUEST_URI} !(.*css)
RewriteCond %{REQUEST_URI} !(.*js)
RewriteCond %{REQUEST_URI} !(.*gif)
RewriteCond %{REQUEST_URI} !(.*png)
RewriteCond %{REQUEST_URI} !(.*jpg)
RewriteCond %{REQUEST_URI} !(contact-us/google-map)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

#If HTTPS, redirect Google Map page to non-HTTPS
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} (contact-us/google-map)
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,L]

# Redirect non-canonical hostname requests to canonical domain 
RewriteCond %{HTTP_HOST} !=www.atfundraising.com 
RewriteCond %{HTTP_HOST} !=test.atfundraising.com 
RewriteCond %{HTTP_HOST} !=oldsite.atfundraising.com 
RewriteCond %{HTTPS}>s ^(on>(s)|[^>]+>s)$ 
RewriteRule ^(.*)$ http%2://www.atfundraising.com/$1 [R=301,L] 
WillHall’s picture

Excellent, glad you got it figured out - sorry I didn't get back sooner - been in meetings since lunch.