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!

 

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.