Post by markmarkus » Wed Jul 26, 2017 1:33 am

Hi, I have just added a store to my Opencart store but the new domain always redirect to the current store.
Newdomain.com redirects always to CurrentDomain.com, unless I disable htaccess.

My htaccess is a bit complicated and I have no idea what should I change to solve it, every idea will be welcomed.

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/  

# Redirects to https and prevents conflict loop with CloudFlare
# RewriteCond %{HTTP:X-Forwarded-Proto} =http
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirects non www to www address
 RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com
 RewriteRule (.*) https://www.mywebsite.com/$1 [R=301,L]

RewriteBase /
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

<FilesMatch ".(js|css)$">
Header append Cache-Control "private"
</FilesMatch>
<FilesMatch "\.(gif|jpe?g|png)$">
Header set Cache-Control "public"
</FilesMatch>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
## EXPIRES CACHING ##

##SmartOptimizer##
<IfModule mod_expires.c>
   <FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
      ExpiresActive On
      ExpiresDefault "access plus 10 years"
   </FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
   RewriteEngine On
   
   #RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*\.(js|css))$ smartoptimizer/?$1
   
   <IfModule mod_expires.c>
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule ^(.*\.(js|css|html?|xml|txt))$ smartoptimizer/?$1
   </IfModule>

   <IfModule !mod_expires.c>
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule ^(.*\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico))$ smartoptimizer/?$1
   </IfModule>
</IfModule>
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
   FileETag none
</FilesMatch>
##SmartOptimisre##

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by labeshops » Wed Jul 26, 2017 3:12 am

Well, you have some things there I don't recognize, but the part to redirect non-www to www and to https: that I use in my multistores is:

Code: Select all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/download/(.*) index.php?route=error/not_found [L]

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

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
so I would rewrite the above over your:

Code: Select all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/  

# Redirects to https and prevents conflict loop with CloudFlare
# RewriteCond %{HTTP:X-Forwarded-Proto} =http
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirects non www to www address
 RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com
 RewriteRule (.*) https://www.mywebsite.com/$1 [R=301,L]

RewriteBase /
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
Be sure to keep these lines below the above or it breaks things - I added the comment shown so I wouldn't forget that!

Code: Select all

# keep these lines BELOW all other rewrite lines
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Running Opencart v3.0.3.2 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by markmarkus » Wed Jul 26, 2017 3:39 am

Thanks for your reply. Almost there!

The current domain, using https, has not suffered any change, which is good. But the new domain, which is http redirects to an https, so the browser shows an Secure Connection Failed error.

I need the new domain to go to the http version to work. Any suggestion?

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by labeshops » Wed Jul 26, 2017 5:43 am

Change the {server_name} in the code above to the domain you want to go to https:

Running Opencart v3.0.3.2 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by markmarkus » Wed Jul 26, 2017 6:05 am

Doesn't seem to work :( .

Domain1 is ok, non www redirects to www and http redirects to https which is fine.
Domain2 redirects to domain1. I don't have https in Domain2, I want it to go to plain http.

Do you see something wrong in this code?

Code: Select all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/  

# Redirects to https and prevents conflict loop with CloudFlare
# RewriteCond %{HTTP:X-Forwarded-Proto} =http
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#New
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain1.com/$1 [R,L]

RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by MrPhil » Wed Jul 26, 2017 8:51 am

markmarkus wrote:
Wed Jul 26, 2017 6:05 am
Domain1 is ok, non www redirects to www and http redirects to https which is fine.
Domain2 redirects to domain1. I don't have https in Domain2, I want it to go to plain http.
Desired behavior:
  • domain1: http->https and non-www to www
  • domain2: http left as http and non-www to www
Right?

Do you see something wrong in this code?
Yes, a couple things.

Code: Select all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/  

# Redirects to https and prevents conflict loop with CloudFlare
# RewriteCond %{HTTP:X-Forwarded-Proto} =http
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#New
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If not www, it redirects both domain1 and domain2 to https (as well as www).

Code: Select all

RewriteEngine On
Unnecessary a second time, you can remove this.

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain1.com/$1 [R,L]
If non-www, both domain1 and domain2 redirected to domain1 (under www)

Code: Select all

RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
This part looks OK, although you may need to add a RewriteCond before it.

Try this for revised code:

Code: Select all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/  

# Redirects to https and prevents conflict loop with CloudFlare
# RewriteCond %{HTTP:X-Forwarded-Proto} =http
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# domain1: force www and https
RewriteCond %{HTTP_HOST} !^www\.  [NC,OR]
RewriteCond %{HTTPS}  off
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$  [NC]
RewriteRule ^(.*)$ https://www.domain1.com/$1 [R=301,L]

# domain2: force www and http
RewriteCond %{HTTP_HOST} !^www\.  [NC,OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$  [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
Note that https for domain2 will be changed to http.

Code: Select all

RewriteCond  %{HTTP_HOST}  ^www\.  [NC]    <<<------ I'm not sure if you'll need this, but it won't hurt
RewriteRule ^googlebase.xml$...[L]      <<<------ rest of code
Are these stores installed in different directories? If so, you may find it cleaner to just do the redirecting for a particular store within its own directory, rather than trying to handle both stores at once in the root .htaccess. If one store is in the root, you may not be able to do that.

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by markmarkus » Wed Jul 26, 2017 4:20 pm

Both stores are in the same folder, I have 2 different domains pointing to that folder.

I have updated the htaccess with this new config:

When I use https://www.domain2.com I get a Secure Connection Failed error. But I guess no one will type https in the url bar.
When I use http://www.domain2.com I get a redirect loop, I see this in the inspection tab:

Error 301 - Get www.domain2.com
Error 301 - Get domain2.com
Error 301 - Get www.domain2.com
Error 301 - Get domain2.com... and so on.

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by markmarkus » Wed Jul 26, 2017 5:37 pm

[Update]

Now it works perfectly! I added this line:

RewriteCond %{ENV:HTTP} !on [NC]

However I see that my website is so customized that a lot of modules are not working in the domain2 version, I'll have to consider if the effort is worthwhile.

Thanks a lot!

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by markmarkus » Fri Jul 28, 2017 5:01 am

New issues :( . The redirections are all ok, however If people pay using credit card the money is charged but I don't get the order in my email, neither does the customer, also the stock is not discounted. The technical support tell me that the confirmation has to go to an http and cannot use a redirection as it is my case.

Last year to make it work I had to change this code:

Code: Select all

 $redsys->setParameter("DS_MERCHANT_MERCHANTURL",$this->config->get('config_url') . 'index.php?route=payment/servired/callback');

for this one:

Code: Select all

 $redsys->setParameter("DS_MERCHANT_MERCHANTURL",str_replace('https://','http://',$this->config->get('config_url')) . 'index.php?route=payment/servired/callback');
And worked ok until the new redirections set two days ago. Any suggestions? Thanks in advance.

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by MrPhil » Fri Jul 28, 2017 10:55 pm

markmarkus wrote:
Fri Jul 28, 2017 5:01 am
The technical support tell me that the confirmation has to go to an http and cannot use a redirection as it is my case.
I find that very hard to believe. You probably misunderstood something they said. If you are sending to a page on your site, and it's an http: URL, and you redirect to https:, it doesn't work? Can you change your payment service configuration to send to https: directly (with www., too)? Maybe it doesn't like getting a redirect, fearing that someone is diverting your store traffic or something else malicious. You have to have cooperation on their end to accept the redirect and resend to the right place (a 30x redirect for a browser throws the whole thing back to the browser, and says "try again, at this address this time").
Last year to make it work I had to change this code:
This was before you switched to https:? I take it that DS_MERCHANT_MERCHANTURL is your return-to page, and not the payment service? Is it really "servired" or is it "serviced"? Anyway, have you updated that macro name to be https:, and removed the change to http:? Is the http: store using a different callback page?

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by labeshops » Sat Jul 29, 2017 6:28 am

Did you also properly turn on or turn off ssl for each domain in settings and set their ssl path?

Running Opencart v3.0.3.2 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by markmarkus » Sat Jul 29, 2017 7:11 am

Yes, the technical service gave me a list for the credit card payment system to work properly:
-It has to be accesible from the Internet
-It must not ask for a user or a password
-It has to get the parameters for Post
-It must not redirect to other urls

So the redirection is a problem. I ask them to change the control panel on their side of the payment system to https, they did, but I had the same problem. When I put the old htaccess it worked again properly, even though the https is still on. Very strange.

Regarding setting https correctly in every domain, yes, domain1 is a https domain and is set like that in the OC settings. Domain2 is set with http since it's not SSL.

The technical service also told me that the redirection to https in opencart was not necessary since establishing it like that in the settings options would redirect automatically all http to https. I've tried but this doesn't seem to be true, http remains like that when I manually take the 's' from https. However with the htaccess redirection all url combinations redirect to https://www

New member

Posts

Joined
Thu Dec 26, 2013 7:51 am

Post by MrPhil » Sat Jul 29, 2017 11:10 pm

More and more stores (and websites in general) are moving to https: for all access. You should be able to use https: for your store, and configure it to use https: for all generated links (any link uses https: ). Also, any return to your site from a third-party payment processor should be configured to use https:. The .htaccess redirect from http: to https: is only used for old bookmarks, old search engine entries, and people who typed http: instead of https:. Your site should be producing https: links everywhere.

User avatar
Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm
Who is online

Users browsing this forum: No registered users and 61 guests