Jump to content

Using a .htaccess to redirect to a secure site ??


spacepoet

Recommended Posts

Hello:

 

I'm trying to redirect my current site to point to the secure site, and am having a problem getting it to work for all instances.

 

I currently have this:

.htaccess

RewriteEngine on
RewriteRule ^$ https://www.mysite.com/index.htm

 

This works fine when using the URLs "www.mysite.com" and "http://www.mysite.com"

 

But when I enter "mysite.com" it directs to something like "https://www.mysite.com/www.mysite.com" which is incorrect.

 

Also, if I enter a URL like "http://www.mysite.com/about.htm" it does not direct to "https"

 

What is the trick to always have the "https" no matter what URL is entered?

 

Any help would be great.

 

Thanks!

 

Link to comment
Share on other sites

Hello:

 

Thanks for the post and the link.

 

This is the one I think I need to use:

RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.+)$ - [env=askapache:%2]

# redirect urls with index.html to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http%{ENV:askapache}://%{HTTP_HOST}/$1 [R=301,L] 

# change // to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)//(.*)\ HTTP/ [NC]
RewriteRule ^.*$ http%{ENV:askapache}://%{HTTP_HOST}/%1/%2 [R=301,L]

 

I want to go from HTTP to HTTPS for all the pages, but not sure I'm following how to do it.

 

Do I need to make a new "RewriteCond/RewriteRule" for every page?

 

I am currently doing this:

RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ https://www.mysite.com/$1 [r=301,nc]

rewritecond %{http_host} ^www.mysite.com [nc]
rewriterule ^(.*)$ https://www.mysite.com/$1 [r=301,nc]

rewritecond %{http_host} ^http://www.mysite.com [nc]
rewriterule ^(.*)$ https://www.mysite.com/$1 [r=301,nc]

rewritecond %{http_host} ^http://www.mysite.com/about.htm [nc]
rewriterule ^(.*)$ https://www.mysite.com/about.htm$1 [r=301,nc]

 

It is working, but isn't there a more streamlined way to change it?

 

Sorry, but I'm not to certain how to do mod rewrites like this.

 

I appreciate the help.

Link to comment
Share on other sites

Sorry, I mean I did it like this:

RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewritecond %{http_host} ^www.mysite.com [nc]
rewritecond %{http_host} ^http://www.mysite.com [nc]
rewriterule ^(.*)$ https://www.mysite.com/$1 [r=301,nc]

 

The other was was NOT working.

 

Should I just hardcode the "https" into the navigation?

<a href="https://www.mysite.com/about.htm">About</a>

 

??

 

I just thought there was a way to change it everywhere via an .htaccess file.

 

Thanks!

 

Any ideas how to fix this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.