HTaccess - redirect a single page to HTTPS and the whole site from www to non www

I have tried to find the answer to this using forums, websites, help pages. I have asked my website host for help, my SSL certificate provider for help, still no answer. I have seen this question posed by many other people previously, but know one has received a reply.

Hopefully someone here will know the answer :slight_smile:

How do I redirect all of my website pages from www to non-www and (at the same time) redirect one single http page to https?

My current HTaccess code is as follows:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^sample\\.com$ [NC]
RewriteRule .* http://sample.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This works for the entire site, but not the single page that I need.

Can anyone on the forum give me the answer. If they can (and it works), I will post the answer everywhere (i’m not the only person who has asked this question :slight_smile:

Thanks in advance, Phil

[FONT=Courier New]Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^sample\.com$ [NC]
RewriteRule .* http://sample.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^one/single/page\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301][/FONT]

Hi Jeff

Thank you for your reply.

I have tried your suggested code. Pages certainly redirects to non-www but the single page still doesn’t load as https.

Just to confirm, I replaced your red text with ^mysite/payment\.html$ I also tried ^http://mysite/payment\\.html$

Is it because the first rule permanently redirects with the 301? I’m fishing here because I really don’t know.

Hope you can help.

Thanks, Phil

Try

^payment\.html$

Hi Jeff

Same result :frowning:

I know the page is SSL compliant because I get the padlock when I don’t use the www redirect. I tested in Opera and Explorer.

wait, wait, wait…stop the press… I refreshed the page a few times, made three wishes, and now it works.

I can’t thank you enough Jeff

Thanks very much :slight_smile:

Mbound,

My signature’s “Article” tutorial has code for precisely what you’ve asked for. Just remember, though, that your secure script should NOT ask for unsecure files so you will need to specify only your served pages (i.e., .php, not .js, not .gif, not .jpg, not .css, etc.) to be redirected.

Regards,

DK

Why not just go SSL for the whole site? You’ve already got the cert in play.