How to make some pages of the site to be in SSL

Hi, i’m new to htaccess, any idea on what i am going to do with my htaccess. First, I want my php pages to be rewriten into html. Secondly, I want some pages/selected pages to be in https. Currently, the code i have will make all pages into https.

Here is my script:

Options -Indexes 
Options +FollowSymlinks 
RewriteEngine On 
RewriteBase /
#Redirect the pages into https:
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
#Rewritting the php pages into html
RewriteRule ^send-inquiry\\.html$ contactus.php
RewriteRule ^user-login\\.html$ user_login.php 
RewriteRule ^user-registration\\.html$ user-registration.php
RewriteRule ^company-tradeshow\\.html$ tradeshow.php 
RewriteRule ^company-aboutus\\.html$ tradeshow.php 

I want http://www.mysite.com/send-inquiry.html, http://www.mysite.com/user-login.html and http://www.mysite.com/user-registration.html to be in https then company-tradeshow.html and company-aboutus.html to be in http.

So, if the first 3 url’s is open as http it should automatically be changed into https. Then, if the 2 url(company-tradeshow.html, company-aboutus.html) was open in https it should automatically be change into http.

Any idea for this to work? Any help is much appreciated. Thank you.

I have this htaccess rule below to redirect my login page, contact page and confirmation page into https but the page is isn’t 100%secured because the css and javascript links was not automatically change into https it is still in http. I got SSL warning “warning contains unauthenticated content”.

htaccess code


RewriteCond %{SERVER_PORT} !^443$ 
RewriteRule ^(login.php|contactus.php|confirmation.php)$ https://%{HTTP_HOST}/$1 [R=301,L] 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule !^(login.php|contactus.php|confirmation.php)$ [%{HTTP_HOST}%{REQUEST_URI}...] [R=301,L] 

This is how i declared css and js links.


<link rel="shortcut icon" href="/images/favicon.ico" /> 
<link href="/css/global.css" type="text/css" rel="stylesheet"/> 
<link href="/css/login.css" type="text/css" rel="stylesheet"/> 
<script type="text/Javascript" language="Javascript" src="/js/checker.js"></script> 

What do i need to do to fixed the ssl warning? Any idea please? Do i need to add something in my htaccess?

cg,

Are those the only files called by this script? No images linked with absolute links? That’s normally the cause of the unauthenticated content.

OIC, the second part of your mod_rewrite is sending EVERYTHING that’s not one of your three scripts to the http server (port 80) so that’s likely the cause of the problem. Perhaps making that regex into a RewriteCond and the RewriteRule should specify .php for the redirection.

BTW, many thanks for this post as I’d not even considered that effect in my mod_rewrite tutorial. I’ll have to take another look at that section in the morning (after I wake up - I’m exhausted now!).

Regards,

DK

There is images too called in the script but i declare it the same way. There is slash(/) in front of it.

Sorry, i’m not really familiar of htaccess. It’s my first time. Can i have sample on how to do it?

Thanks dk

cg,

As noted above, I’ve updated my mod_rewrite tutorial so the code is already in there.

Regards,

DK

dk,

thanks for the reply. I already fixed it. I added this line of code to exclude the images, js and etc,

RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|jpe|ico|css|js)$

CG,

Okay, that’s the inverse of only redirecting your pages (not the support files) but the effect SHOULD be the same.

Regards,

DK

A few question. I want to rewrite my contactus.php into http://www.mysite.com/company/contact-us.html. I have this rewriting rule:


RewriteRule ^company/contact-us\\.html$ aboutus.php [L]

What do i need to edit in my htaccess to make it in https? Do i need to make it like this?

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(company/contact-us.html)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule !^(company/contact-us.html)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$

Will that code work? Thanks

CG,

Okay, you want to rewrite from company/contact-us.html to aboutus.php. No problem, your code will do that just fine.

Unfortunately, your other code block looks … Is the aboutus.php script REALLY the only thing you’ll be sending to HTTPS?

# redirect all HTTPS to HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(company/contact-us.html)$ https://%{HTTP_HOST}/$1 [R=301,L]

# redirect company/contact-us.html to aboutus.php here (HIDDEN!)
RewriteRule ^company/contact-us\\.html$ aboutus.php [L]

# redirect all other pages to HTTP
RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule !^(company/contact-us.html)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# What's this tagging along for?
# RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$

BTW, I still think that you’re likely to miss a support file extension more than you’ll miss a PAGE file extension (i.e., .php) so I’d not use the NOT {support file extension list} and match the page file extension, instead.

Regards,

DK

I still have some other files like the login.php and registration.php. I want to rewrite it too into html like the one i show above and make it redirect into https.

# What's this tagging along for?
# RewriteCond %{REQUEST_URI} !\\.(gif|jpe?g|png|jpe|ico|css|js)$

I used that so i can’t get the SSL warning. Am i doing wrong?

Thanks dk

The developer who worked on our site said he used a switch in configuration to determine if CSS etc were on http or https.

The switch when I asked was the difference between using two sets of URLs - one set for local development (http and https) and second set for live site (again http and https).

cg,

Your list of “support file” extensions is okay but, if you miss ONE, you’ll break the redirection. IMHO, best to list the file types that you WANT to redirect. Six of one, half dozen of the other, though, so, “if it ain’t broke, don’t fix it.”

Regards,

DK