Post by lemonadv » Tue Jan 17, 2017 6:07 am

Hi, I just install SSL certificate to my OpenCart installation.

I want to redirect

http://www.domain.com to https://domain.com
Header check: HTTP/1.1 301 Moved Permanently

http://domain.com to https://domain.com
Header check: HTTP/1.1 301 Moved Permanently

https://www.domain.com to https://domain.com
Header check: HTTP/1.1 301 Moved Permanently

Finally:
https://domain.com
to have header check: HTTP/1.1 200 OK

I made it with this code:

RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]


I'm not sure if this is the right way?
Is there any more simple or right way to do that kind of redirect?

Newbie

Posts

Joined
Fri Apr 08, 2016 2:53 am

Post by thekrotek » Tue Jan 17, 2017 5:29 pm

More simple way? What can be more simple, than adding a few lines to a single file? :-)

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Active Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by artcore » Tue Jan 17, 2017 7:02 pm

You can do it in 3 lines. www to non-www and http to https:

Code: Select all

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) https://yourdomain.com%{REQUEST_URI} [R=301,L,NE]

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by lemonadv » Tue Jan 17, 2017 9:56 pm

Thank you, artcore!
It works perfect!

Newbie

Posts

Joined
Fri Apr 08, 2016 2:53 am

Post by artcore » Tue Jan 17, 2017 10:33 pm

You're welcome,
Cheers

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by ozipekadem » Sun Jan 29, 2017 4:38 am

artcore wrote:You can do it in 3 lines. www to non-www and http to https:

Code: Select all

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) https://yourdomain.com%{REQUEST_URI} [R=301,L,NE]

thank you thats works for me but this time i give error undefined in admin panel and changing any order status. how can i fix this?

Newbie

Posts

Joined
Tue Dec 20, 2011 2:19 am
Location - Istanbul

Post by uksitebuilder » Sun Jan 29, 2017 4:44 am

Make sure you have changed ALL URLs in your config.php and admin/config.php to be your SSL URL

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ozipekadem » Fri Feb 03, 2017 12:13 am

not working :/
uksitebuilder wrote:Make sure you have changed ALL URLs in your config.php and
admin/config.php to be your SSL URL
config.php:

Code: Select all

<?php
// HTTP
define('HTTP_SERVER', 'http://kasecim34.com/');

// HTTPS
define('HTTPS_SERVER', 'https://kasecim34.com/');

admin/config.php:

Code: Select all

<?php
// HTTP
define('HTTP_SERVER', 'http://kasecim34.com/admin/');
define('HTTP_CATALOG', 'http://kasecim34.com/');

// HTTPS
define('HTTPS_SERVER', 'https://kasecim34.com/admin/');
define('HTTPS_CATALOG', 'https://kasecim34.com/');
davidweb09 wrote:By Placing 301 code in your site(HTTP) htaccess file you can easily redirect your site(HTTPS) to a new address...

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) https://domainname.com%{REQUEST_URI} [R=301,L,NE]
thicode already placed.

Newbie

Posts

Joined
Tue Dec 20, 2011 2:19 am
Location - Istanbul

Post by itsmarttricks » Sat Jul 07, 2018 1:37 am

.htaccess redirect www to non-www with SSL/HTTPS
I've got several domains operating under a single .htaccess file, each secured via SSL. I need to force https on every domain while also ensuring www's redirect to non-www's. Here's what I'm using which doesn't work:

RewriteCond %{HTTP_HOST} ^www.%{HTTP_HOST}
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]

Example: https://www.itsmarttricks.com/

should redirect to... https://itsmarttricks.com ::)

Newbie

Posts

Joined
Sat Jul 07, 2018 1:35 am

Post by thekrotek » Sat Jul 07, 2018 11:17 pm

I'd really recommend using Google for this question. There're multiple definitions for .htaccess out there, some of the may work, some not. Stack Overflow has tons of solutions.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Active Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by MrPhil » Sun Jul 08, 2018 1:48 am

itsmarttricks wrote:
Sat Jul 07, 2018 1:37 am
.htaccess redirect www to non-www with SSL/HTTPS
I've got several domains operating under a single .htaccess file, each secured via SSL. I need to force https on every domain while also ensuring www's redirect to non-www's. Here's what I'm using which doesn't work:

RewriteCond %{HTTP_HOST} ^www.%{HTTP_HOST}
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]

Example: https://www.itsmarttricks.com/

should redirect to... https://itsmarttricks.com ::)
Why would you expect the string "<HTTP_HOST>" to ever match "www.<HTTP_HOST>"? It never will. %{HTTP_HOST} is whatever the visitor typed in for the domain name: domain.com or www.domain.com. Try this for each domain:

Code: Select all

RewriteCond  %{HTTP_HOST}  ^domain1\.com
RewriteCond  %{HTTPS}  !on  [OR]
RewriteCond  %{HTTP_HOST}  ^www\.domain1\.com   
RewriteRule  ^(.*)$   https://domain1.com/$1  [R=301,L]
I think that should work on most servers. Note that you need to understand what format each domain comes in as... if maindomain.com/add-on.name/, you'll need to do something different.

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by thekrotek » Sun Jul 08, 2018 1:57 am

MrPhil wrote:
Sun Jul 08, 2018 1:48 am
I think that should work on most servers. Note that you need to understand what format each domain comes in as... if maindomain.com/add-on.name/, you'll need to do something different.
You don't actually need to define a domain in .htaccess. For me this definition works:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
See? No domain!

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Active Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by MrPhil » Sun Jul 08, 2018 9:49 pm

That may work for setups with only one domain in action, but my concern is add-on domains and subdomains, especially if they are presented in the form "protocol://maindomain/subdirectory/". You don't want to do a 301 redirect on an add-on or sub-domain and have the customer see the subdirectory form! Just be careful to test any form of the rewrite code that it doesn't expose the underlying structure. If it is now showing the subdirectory form, you'll need to add a redirect to the add-on or sub-domain form (still in one redirect so you aren't penalized), which probably means one section per add-on or sub-domain (looking at the %{REQUEST_URI} to see the subdirectory).

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by neosphere » Mon Jul 16, 2018 8:08 pm

artcore wrote:
Tue Jan 17, 2017 10:33 pm
You're welcome,
Cheers
Great work. This helped me too....!!!!

User avatar
Newbie

Posts

Joined
Thu Jan 04, 2018 9:55 pm
Location - Kathmandu, Nepal
Who is online

Users browsing this forum: No registered users and 9 guests