Gossamer Forum
Home : General : Internet Technologies :

Forwarding to https using .htaccess

Quote Reply
Forwarding to https using .htaccess
Hi All

I'm trying to force https for a certain directory:

/special_dir

I also want to factor in calls for both

www.domain.com/special_dir
domain.com/special_dir

Thus, anything to:

http://www.domain.com/special_dir
http://domain.com/special_dir

would be redirected to:

https://www.domain.com/special_dir

I have tried the following in htaccess, but I get a browser error stating that I don't have permission to access that area

Code:
RewriteEngine On

# Redirect http:// to https://www.

Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R=permanent,L]

Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R=permanent,L]

Can anyone see how to correct this? Many thanks Smile

------------------------------------------

Last edited by:

DogTags: Apr 23, 2005, 7:15 AM
Quote Reply
Re: [DogTags] Forwarding to https using .htaccess In reply to
Just tried this and it works:

RewriteEngine On

RewriteCond %{SERVER_PORT} !=443

RewriteRule ^ https://yourdomain.tld%{REQUEST_URI} [NS,R,L]

Not sure if the above serves your purpose. Could adjust to your condition.

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] Forwarding to https using .htaccess In reply to
Yeeeeeehaaaaaah!!!!

It works great!!!

I've been trying to find something like this for ages Smile

Thanks so much Smile Smile

------------------------------------------

Last edited by:

DogTags: Apr 24, 2005, 10:44 AM
Quote Reply
Re: [DogTags] Forwarding to https using .htaccess In reply to
Glad that it worked.
5 Minutes was worth the time that i spent on Google :)
First i thought of how cPanel redirects but that was too complicated for me to understand (talking of cpanel as you seem to be on cPanel server).

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [DogTags] Forwarding to https using .htaccess In reply to
Add this if you have not already added to .htaccess

Options +FollowSymLinks

I must have missed while doing and cut and paste

Thanks
HyTC
==================================
Mail Me If Contacting Privately Is That Necessary.
==================================
Quote Reply
Re: [HyperTherm] Forwarding to https using .htaccess In reply to
Yep, cPanel. I have looked at htaccess stuff tons but couldn't see how to work this. Thanks Smile

------------------------------------------