If this is your first visit, check our documentation. To post, register or login.

URL redirection

Started by dml73 on 22 Mar 2014, 3:49 AM · Views: 4,008

Results 1 to 16 of 16
22 Mar 2014, 3:49 AM
#1
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #1 by dml73

Lets say I have a domain called https://www.example.de in German and one called https://www.example.co.uk in English. I have English (default) and German language packages installed in my Zencart.
When users go to https://www.example.de I want them to land on the German version and if they go to https://www.example.co.uk I want them to land on the English version.
I assume that I will need some kind of URL redirection in my host's cPanel, but how is this exactly done? How can I redirect https://www.example.de to the German version of Zencart and https://www.example.co.uk to the English version?? :blink:

22 Mar 2014, 4:02 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #2 by mc12345678

DML73:

Lets say I have a domain called https://www.example.de in German and one called https://www.example.co.uk in English. I have English (default) and German language packages installed in my Zencart.
When users go to https://www.example.de I want them to land on the German version and if they go to https://www.example.co.uk I want them to land on the English version.
I assume that I will need some kind of URL redirection in my host's cPanel, but how is this exactly done? How can I redirect https://www.example.de to the German version of Zencart and https://www.example.co.uk to the English version?? :blink:

So, pleaase forgive me that I don't have significant experience with redirection from a url alone, but basically I would think that you would use your htaccess, such that if the host was, x: and the "language" option was not present then to set the language redirect to the applicable language. If it was set leave it alone...

This would be accomplished using the url rewrite options/settings. But that is my late night Friday ideas. :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

22 Mar 2014, 11:46 PM
#3
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #3 by dml73

Thanks for the suggestion. I now found out that I first have to point both domain names to the same server, and then setup the right code in htaccess. Does anybody have an example of the code I would need to enter in htaccess?

23 Mar 2014, 3:18 AM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #4 by mc12345678

DML73:

Thanks for the suggestion. I now found out that I first have to point both domain names to the same server, and then setup the right code in htaccess. Does anybody have an example of the code I would need to enter in htaccess?

Hmm, so I'm personally trying to figure out how this would be done as well... Are uplanning on having a single set of files to reference, but just the correct language show up? If done this way, seems you will have to pick a domain name to use as the base server name, otherwise you could have two directories for your store, both pointing to the same database, that way the uri would remain as whatever one they entered. Maybe use a plugin that "manages" multiple sites. Reason for the multiple site perspective though would be that the mailing address of the german sitemay need to be different than the mailing address to the other site as entered in the my store area of the store.

So, thinking that you would want to describe here how you want to have your site setup/look to be able toget the answers you seek.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Mar 2014, 8:23 AM
#5
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #5 by rodg

DML73:

Thanks for the suggestion. I now found out that I first have to point both domain names to the same server, and then setup the right code in htaccess. Does anybody have an example of the code I would need to enter in htaccess?

Try this:
http://www.htaccesstools.com/redirection-by-language/

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

26 Mar 2014, 9:03 AM
#6
setyadwi avatar

setyadwi

New Zenner

Join Date:
Mar 2014
Location:
Indonesia
Posts:
1
Plugin Contributions:
0

Post #6 by setyadwi

RodG:

Try this:
http://www.htaccesstools.com/redirection-by-language/

Cheers
RodG

I will try it on my site, and again asked if an error occurs. Thank you

29 Mar 2014, 12:58 AM
#7
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #7 by dml73

I have two domain names pointing to the same server:
https://www.example.co.uk (English language)
and
https://www.example.de (German language)

The content is the same except that https://www.example.co.uk is in English and https://www.example.de is in German.

How can I by using htaccess force a visitor that goes to:
http://www.example.co.uk
to land on:
http://www.example.co.uk/index.php?main_page=index&language=en
and stay within the English language pack regardless of which page he navigates to (except if he manually change the language at the language selection bar).

And the same for www.example.de:
force a visitor that goes to:
http://www.example.de
to land on:
http://www.example.co.uk/index.php?main_page=index&language=de

I have been trying to use this:
RewriteCond %{HTTP_HOST} ^www.www.example.co.uk [NC]
RewriteRule ^(.)$ index.php?language=en [NC,QSA]
RewriteCond %{HTTP_HOST} ^www.www.example.de [NC]
RewriteRule ^(.
)$ index.php?language=de [NC,QSA]

but this appears to do nothing.
Any help is much appreciated.

29 Mar 2014, 5:24 AM
#8
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #8 by rodg

DML73:

I have been trying to use this:
RewriteCond %{HTTP_HOST} ^www.www.example.co.uk [NC]
RewriteRule ^(.)$ index.php?language=en [NC,QSA]
RewriteCond %{HTTP_HOST} ^www.www.example.de [NC]
RewriteRule ^(.
)$ index.php?language=de [NC,QSA]

but this appears to do nothing.
Any help is much appreciated.

I think you're on the right track, BUT......

^www.www\.example.......................

This will almost certainly never find a match. Re-write these as
^www.example............ (only one 'www')

Also, in the 1st RewriteCond you are missing the escape character "" before the "." in "uk".
Should be
RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk [NC]

In addition to this, it would be prudent to check for the same conditions without the 'www'.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

29 Mar 2014, 7:28 AM
#9
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #9 by dml73

Thanks for the comment RodG, it now seems to be partly working, when I land on the index pages; https://www.example.co.uk is in English and https://www.example.co.uk is in German however as soon as I click on a link on the English site it changes to https://www.example.de and the German language.
When I go to https://www.example.de it does stay on the German language however, even when I click a link.
It also appears as the css file and image directory are not being read because the sites are displayed without images and css styling.

I suspect at least there is something wrong with the rewrite rule:

RewriteRule ^(.*)$ index.php?language=de [NC,QSA]

Should the "index.php?language=de" be changed to something different?

29 Mar 2014, 2:36 PM
#10
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #10 by rodg

DML73:

Should the "index.php?language=de" be changed to something different?

Sorry, but I honestly couldn't say. I'm really not all that familiar with how ZenCart handles different languages. In fact if it wasn't for your example I would never have thought about rewriting the URL's to select a different language.

My previous input was based purely on the things that I could see were wrong, which isn't quite the same thing as telling you the things that could be right.

Offhand, I can't see what would be wrong with this current rewriteRule. It looks like it should be right.

What are you seeing in the browser URL for any given request?

What you should be seeing (if the rewrites are working correctly) is something like

[URL="http://www.example.de/index.php?main_page=index&cPath=57"]www.example.de/index.php?main_page=index&cPath=57[/URL]  being rewritten as 
[URL="http://www.example.de/index.php?"]www.example.de/index.php?[/URL]language=de&main_page=index&cPath=57  or 
[URL="http://www.example.de/index.php?main_page=index&cPath=57&"]www.example.de/index.php?main_page=index&cPath=57&[/URL]language=de  

and 
[URL="http://www.example.uk/index.php?main_page=index&cPath=57"]www.example.uk/index.php?main_page=index&cPath=57[/URL]  being rewritten as 
[URL="http://www.example.uk/index.php?"]www.example.uk/index.php?[/URL]language=en&main_page=index&cPath=57 or  
[URL="http://www.example.uk/index.php?main_page=index&cPath=57&"]www.example.uk/index.php?main_page=index&cPath=57&[/URL]language=en 

Again, I've no idea whether these will give you the results you desire because that would depend on how the URI is parsed by ZenCart, but it will confirm whether the rewrites are being performed or not.

Cheers
RodG

ps. Could you give us/me the URL for the site(s). Offhand I don't know of any site that is using multiple languages (Although I'm sure there are lots of them around), and it would be useful to see this in action.

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

29 Mar 2014, 5:48 PM
#11
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #11 by dml73

RodG:

What are you seeing in the browser URL for any given request?

It seems like the rewrites are are not working because I don't see the "&language=de" and "&language=en" at the end of each URL (unless I manually select a language). Also there is no styling as if the css file for some reason is not read. Very strange :blink:

What I have in htaccess is:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.de [NC] 
RewriteRule ^(.*)$ index.php?language=de [NC,QSA] 

RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk [NC] 
RewriteRule ^(.*)$ index.php?language=en [NC,QSA]

Typical URL's without a language is selected are:

http://www.example.co.uk/index.php?main_page=index&cPath=65
http://www.example.co.uk/index.php?main_page=product_info&cPath=65&products_id=180
http://www.example.co.uk/index.php?main_page=contact_us

and when a language is selected then they are:

http://www.example.co.uk/index.php?main_page=index&cPath=65&language=en
http://www.example.co.uk/index.php?main_page=product_info&cPath=65&products_id=180&language=en
http://www.example.co.uk/index.php?main_page=contact_us&language=en

What could be wrong with the htaccess statements?

Unfortunately I currently can't give you the URL for the site because it's down for maintenance to avoid search engines to index the pages yet as that would result in duplicate content because most of the contest on the two domains is still only in English as I haven't translated the .de domain to German yet.

30 Mar 2014, 8:42 PM
#12
iray avatar

iray

New Zenner

Join Date:
Jun 2007
Posts:
72
Plugin Contributions:
0

Post #12 by iray

It depends what you want.

If you want to set the language in cookies by visiting one of those domains then you need:

RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.|)example\.co\.uk$ [NC] 
RewriteRule ^$ index.php?language=en [L] 
RewriteCond %{HTTP_HOST} ^(www\.|)example\.de$ [NC] 
RewriteRule ^$ index.php?language=de [L]

If you want to redirect, then:

RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.|)example\.co\.uk$ [NC] 
RewriteRule ^$ index.php?language=en [R=301,L] 
RewriteCond %{HTTP_HOST} ^(www\.|)example\.de$ [NC] 
RewriteRule ^$ index.php?language=de [R=301,L]
31 Mar 2014, 1:38 AM
#13
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #13 by dml73

Thanks a lot iRAY, now its almost working! Im using what you mentioned to redirect :

RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.|)example\.co\.uk$ [NC] 
RewriteRule ^$ index.php?language=en [R=301,L] 
RewriteCond %{HTTP_HOST} ^(www\.|)example\.de$ [NC] 
RewriteRule ^$ index.php?language=de [R=301,L]

This gives me "http://www.example.co.uk/index.php?language=en" when I go to "www.example.co.uk" and "http://www.example.de/index.php?language=de" when I go to "www.example.de", exactly as I want. However, as soon as I click a link on the index page the "language=de" or "language=en" disappears.
So one question remains: How do I apply this rule to all pages? not only the index page.

31 Mar 2014, 4:50 AM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #14 by drbyte

DML73:

However, as soon as I click a link on the index page the "language=de" or "language=en" disappears.That's by design.
Zen Cart automatically removes the language=XX parameter from the URL on next click, because it's already been set into the customer's browsing session (associated with the session cookie which Zen Cart sets when the page is displayed).
DML73:

So one question remains: How do I apply this rule to all pages? not only the index page.You don't.

MODERATOR NOTE: Your 2 duplicate threads have been merged. Not sure why you started a second one to re-discuss the same issue again.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

31 Mar 2014, 5:41 AM
#15
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
416
Plugin Contributions:
0

Post #15 by dml73

Thanks for the information Dr.Byte and everybody else. It seems like this is finally working. Here is a summary of how I accomplished this:

  1. Point both domain names to the same server (via domain name registrar).

  2. One domain name must be the main domain on the server, the other must be “parked” (via web hosting company).

  3. Use below statements in root htaccess:

RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.|)example.co.uk$ [NC]
RewriteRule ^$ index.php?language=en [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.|)example.de$ [NC]
RewriteRule ^$ index.php?language=de [R=301,L]

  1. To prevent a visitor is automatically directed to the main domain when he clicks a link on the parked domain change:

define('HTTP_SERVER', 'http://www.example.de');
define('HTTPS_SERVER', 'https://www.example.de');

in includes/configuration.php to:

define('HTTP_SERVER', '');
define('HTTPS_SERVER', '');

So I guess what is missing is to avoid search engines double-indexing where same language is selected on both domains, as for example:

http://www.example.co.uk/index.php?main_page=index&cPath=65 (English language selected)
http://www.example.de/index.php?main_page=index&cPath=65 (English language selected)

I guess I will need to disable the language selecting bar so visitors (and search engines) won't have the possibility to select above example; and instead just put a link to each language domain https://www.example.co.uk and https://www.example.de

Im not sure if this is the correct way to do all this but apparently it seems to be working so far.

31 Mar 2014, 8:04 PM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #16 by drbyte

Keep in mind that Zen Cart has a setting that lets you have it auto-negotiate the customer's selected language based on the customer's own preferences they've set in their browser ... therefore giving them the optimal experience regardless of the URL they visited.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.