spacepoet Posted September 20, 2011 Share Posted September 20, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/247539-using-a-htaccess-to-redirect-to-a-secure-site/ Share on other sites More sharing options...
xyph Posted September 20, 2011 Share Posted September 20, 2011 http://www.askapache.com/htaccess/http-https-rewriterule-redirect.html Quote Link to comment https://forums.phpfreaks.com/topic/247539-using-a-htaccess-to-redirect-to-a-secure-site/#findComment-1271160 Share on other sites More sharing options...
spacepoet Posted September 21, 2011 Author Share Posted September 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247539-using-a-htaccess-to-redirect-to-a-secure-site/#findComment-1271215 Share on other sites More sharing options...
spacepoet Posted September 21, 2011 Author Share Posted September 21, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/247539-using-a-htaccess-to-redirect-to-a-secure-site/#findComment-1271216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.