Thread: URL redirection

Results 1 to 10 of 16

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    412
    Plugin Contributions
    0

    Default Question for htaccess experts regarding two domains and language packs

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

    The content is the same except that www.example.co.uk is in English and 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?m...ex&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?m...ex&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.

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Question for htaccess experts regarding two domains and language packs

    Quote Originally Posted by DML73 View Post
    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

  3. #3
    Join Date
    Oct 2007
    Posts
    412
    Plugin Contributions
    0

    Default Re: Question for htaccess experts regarding two domains and language packs

    Thanks for the comment RodG, it now seems to be partly working, when I land on the index pages; www.example.co.uk is in English and www.example.co.uk is in German however as soon as I click on a link on the English site it changes to www.example.de and the German language.
    When I go to 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?

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Question for htaccess experts regarding two domains and language packs

    Quote Originally Posted by DML73 View Post
    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
    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.
    Last edited by RodG; 29 Mar 2014 at 03:41 PM.

  5. #5
    Join Date
    Oct 2007
    Posts
    412
    Plugin Contributions
    0

    Default Re: Question for htaccess experts regarding two domains and language packs

    Quote Originally Posted by RodG View Post
    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

    What I have in htaccess is:

    Code:
    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:
    Code:
    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:
    Code:
    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.

  6. #6
    Join Date
    Jun 2007
    Posts
    70
    Plugin Contributions
    1

    Default Re: Question for htaccess experts regarding two domains and language packs

    It depends what you want.

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

    Code:
    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:

    Code:
    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]

  7. #7
    Join Date
    Oct 2007
    Posts
    412
    Plugin Contributions
    0

    Default Re: Question for htaccess experts regarding two domains and language packs

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

    Code:
    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.

 

 

Similar Threads

  1. Page redirection
    By chandroo007 in forum General Questions
    Replies: 3
    Last Post: 29 Oct 2010, 06:57 AM
  2. admin redirection
    By icehokz in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 19 Mar 2009, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg