Forum Moderators: phranque

Message Too Old, No Replies

Help with .htaccess file

redirecting several domains

         

androvboy

12:03 am on Nov 2, 2004 (gmt 0)

10+ Year Member



Just setting up a new multi-lingual and multi-currency website. Default site is say example.com/index.php

Now I also have the example.de (for germany) domain registered and want this to go straight to the german language version and prices in Euros.

So the URL to switch would be example.com/index.php?language=2&currency=2

Basically if I add?language=2&currency=2 on the end of every page it produces the result. I could use php or a straight redirect page but I want the search engines to READ german when they go to example.de - so each site gets indexed independently I hope. (they do have different content!)

Can I do this with .htaccess? I guess I want
example.de to show the contents of example.com/index.php?language=2&currency=2, and of course all the other pages produced by the site.

I have dedicated server so lots of control - just dont know what I am doing! Thanks :-)

fish_eye

1:00 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



Not sure I follow - would you be happy / happier to have engines and humans both find and see example.de/index.php without the?language=2&currency=2 and never see example.com/index.php?language=2&currency=2?

androvboy

1:33 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



Yes I am happy for robots and humans to see example.de/index.php without ever seeing example.com/index.php?language=2&currency=2

It seems like the site "remembers" your settings once you have gone past this index page.

Obviously some pages get longer such as:

[example.com...]

(the above includes a session URL for when cookies are disabled).

or simpler with cookies such as:

[example.com...]

I am confused as to whether I need to use:

1. DirectoryIndex command
2. Proxypass
3. Rewrite

Sounds like Proxpass might be something like what I need? Because in effect I want example.de to serve up results from example.com

In my dream scenario I would host each domain "locally" (e.g. the .de on a German server), and pull the pages from the main site. This would probably keep the engines happiest!

fish_eye

12:31 am on Nov 3, 2004 (gmt 0)

10+ Year Member



Firstly I should point out that you are working in an area where I have only a little experience. I use a virtual hosting company so they do a lot of the hack work for me and.... what they do for me is point all my domain names to subdirectories within the same physical space (that all share the same database).

In other words I would have public_html/_com and public_html/_de and the domain names would simply be pointed at the relevant sub-directories (though I'm not sure what technique they use for this).

Are your EN and DE sites totally separate content? Pressuanbly not, so what do they share (eg.identical images and identical structure)?

If so (and using my set up above) I would have to duplicate the structure (or have this built into a database - which means the actual page names would be identical) and share the images directory. I would probably also have a single database of items for sale (if that's what you're doing) and have values and currency codes against each item (or a formula with rounding).

To the outside world the sites would have identical structure with images in identical places but text would be completely different (but in identical places). This is what you want I guess?

Sorry if I'm straying off the topic - or stating the bleeding obvious - it's an area I've become a little interested in lately hence my interest here.

Jim - if you're there - is there a post that goes into this or a how-to guide for internationalisation using apache?

I did a quick search and found this [vancouver-webpages.com] but I'm not sure if it addresses the multiple domain name topic - only had a quick look.

If you do find a good resource can you let me know please?

androvboy

10:15 am on Nov 3, 2004 (gmt 0)

10+ Year Member



I hear you - but not quite what I am after. There are ways I might duplicate the site and pull content from the same database...........but ideally I am looking for a simpler solution using Apache.

I will post if I find the solution!

jdMorgan

8:31 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, make sure that there are no pages on your site contining links with "?language=2&currency=2" in them. All should simply refer to pages in the .de domain.

Then use mod_rewrite to rewrite (not redirect) any request for pages in the .de domain to the same page, but with the "?language=2&currency=2" query string appended.

In simplified form, an example for .php pages would be:


RewriteCond %{HTTP_HOST} \.de(:[0-9]{1,5})?$
RewriteRule ^(.+)\.php$ /$1.php?language=2&currency=2 [L]

Before beginning to modify your site, I strongly suggest that you study the resources cited in our charter [webmasterworld.com], and get very comfortable with mod_rewrite and its capabilities; A single error in the design or implementation of this kind of site-wide-rewrite code can take your whole site down.

Jim

androvboy

11:17 pm on Nov 3, 2004 (gmt 0)

10+ Year Member



So I park the extra .de domain onto my main domain and then just add and test the .htaccess file perhaps?
(or is it better to point the domain at the IP address?)

Looking at the way my site operates it might be in fact that I only need/want to redirect the very first index page.

So I need I think example.de to go to example.com/index.php?language=2&currency=2
but from there looks like I only need to change the first part of the URL (from .com to show .de)

I have been trying to read up on this the last few days but it still feels like Egyptian to me at this stage (but I did get some basic commands working on a test site).

Thanks so far!

jdMorgan

1:27 am on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> So I park the extra .de domain onto my main domain and then just add and test the .htaccess file perhaps?
(or is it better to point the domain at the IP address?)

Yes, point the domain to the IP address -- forget all that "parking" and "frame-forwarding" stuff if you want a happy life -- or good search enigne ranking! :)

The typical approach would be to structure the site like this:

Point all top-level-domain/country-code domains to the server IP address.

Detect the country code in the domain name, and pass that to a (new) script as a parameter.
New script looks up the correct language and currency parameters and passes that to the original script.

For a small site with just a few tlds and country-codes, you can do it all with mod_rewrite:


RewriteCond %{HTTP_HOST} example\.de
RewriteRule ^(.+)\.php$ /$1.php?language=2&currency=2 [L]
RewriteCond %{HTTP_HOST} example\.co\.uk
RewriteRule ^(.+)\.php$ /$1.php?language=3&currency=2 [L]
RewriteCond %{HTTP_HOST} example\.com
RewriteRule ^(.+)\.php$ /$1.php?language=4&currency=3 [L]
RewriteCond %{HTTP_HOST} example\.fr
RewriteRule ^(.+)\.php$ /$1.php?language=5&currency=2 [L]

There are many ways to do it; You can also use mod_rewrite in httpd.conf and use the RewriteMap function to lookup language and currency. Or you can make a lookup script as described above. Or you can build the function into your new script, and just pass the dountry-code to the script.

Jim

androvboy

1:10 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



I tried the following in the .htaccess file for the main domain (example.biz) to try and redirect the .co.uk (which is pointing straight at the fixed IP number for the site now).

RewriteEngine on
RewriteCond %{HTTP_HOST} \.co\.uk(:[0-9]{1,5})?$
RewriteRule ^(.+)\.php$ /$1.php?language=1&currency=1 [L]

The .co.uk is directing to the IP number correctly, but I get a 500 Internal Server Error, plus it says a 404 error was found!

The example.biz 1st page is index.php but this is the content of the php file if that matters at all:

<?php
include("static/includeBase_front.php");

$xSec=1;
$thisTemplate = "index.html";

dbConnect($dbA);

include("routines/cartOutputData.php");

$tpl->showPage();
$dbA->close();
?>

Firstly I want example.co.uk just to show the contents of example.biz for every page.

So if you go to say example.co.uk/mypage.php you SEE the results from example.biz/mypage.php (so straight switch of the 1st part of the URL only) - but stays as example.co.uk/mypage.php in the browser.

Then secondly just for that first index.php page I need?language=1&currency=1 added on the end. (I think once changed at the homepage the cookie or session ID remembers from there on).

So when someone goes to example.co.uk it really displays the page contents from example.biz/index.php?language=1&currency=1

I honestly have tried to read the Apache guides, and I am not generally daft, but things like ^(.+)\.php$ just completely lose me!

Thanks,

Jonathan.

jdMorgan

3:39 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> but I get a 500 Internal Server Error.

What does your server error log say? That's the first place to look when you get a server error.

You may need to add Options +FollowSymLinks to your code to enable mod_rewrite.

If "^(.+)\.php$" loses you, then review the regular expressions tutorial cited in our forum charter. Regular expressions form one-half of the foundation you'll need to use mod_rewrite successfully, and there is no use trying to go forward without being comfortable with them.

To get you started, "^(.+)\.php$" means "a string starting with at least one character, followed by a literal period, and ending with "php". The parentheses tell mod_rewrite to remember the contents from the start of the string up to the literal period, so that this information can be used (back-referenced) by the substitution URL (in other words, remember that part of the requested URL so that we can "copy" it into the new URL). The "\" marks the period that follows it as being a literal period, instead of being a "special" character that regular-expressions defines as meaning "any single character".

The learning curve is admittedly quite steep on this stuff. For one thing, complex regular expressions are much easier to write when you know the desired goal than they are to read when you don't. But once you gain basic understanding of mod_rewrite, you will realize how immensely powerful a tiny bit of good mod_rewrite code can be -- and how terribly destructive a tiny bit of bad code can be, too.

Jim