Welcome Guest, Not a member yet? Register   Sign In
http to https using .htaccess
#1

[eluser]Unknown[/eluser]
I was bogged down with this problem a couple of weeks ago, I had to rewrite a couple of urls to https. The rest of the url should be on http, that means if they are on https they should be written to http.

I couldnt get the solutions easily, so I m posting it here.

---------------------------
first of all you need to change your base url to

Code:
$config['base_url'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://' ;
$config['base_url'] .= $_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';

with this for a https page all the links created with base_url() will automatically be https.

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

Secondly, you need the following entry to ur .htaccess file, tweak it as per the requirement

Code:
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)/(view|checkout|pay)(.*)$ https://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]

RewriteCond %{HTTPS} on
RewriteRule ^(.*)/(success)(.*)$ http://%{HTTP_HOST}/cart/$2$3 [R=301,NC,L]
  
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_REFERER} !^https(.*)/(view|checkout|pay)(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^(.*)/(view|checkout|pay)(.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

the condition RewriteCond %{HTTP_REFERER} !^https(.*)/(view|checkout|pay)(.*)$ [NC] doesnt rewrite the links to http which are on a https page.

-------------------------------------------------------
you can go through this stackoverflow link for a little more details
http://stackoverflow.com/questions/18188...ps-to-http


Hope this helps someone ..

regds,
Shikhar




Theme © iAndrew 2016 - Forum software by © MyBB