homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirect MSIE browse + ES and DE traffic
Redirecting all MSIE browsers and all German and Spanish traffic
iliumx




msg:4318768
 7:32 pm on May 27, 2011 (gmt 0)

Hello,

I've several times had help reading the webmasterworld.com posts, but this is my first post. I need help with something. Please help. I'm a amateur regarding htaccess, so please bear with me as I try to explain what I need done.

I want to redirect all versions of IE browsers from one page to another internal page (not 301 redirect), and also redirect all Spanish and German traffic/users to the same pages. I have 4 specific pages that I need to do this on.

* Regarding of IE users

I have figured out a working solution. The code for this is:

RewriteEngine On (is at the top of the htaccess file)

# Redirect all users that use the browser MSIE from one htm file to another
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteRule ^(PAGE1.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE2.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE3.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE4.htm)$ http://example.com/NEW.htm [R,NC,L]


At least this works on IE 8, but I have read somewhere that this (.*MSIE.*) should work the same for all IE browsers (4,5,6,7,8,9).

I'm curious if that code will still work when I also need to add some code that will redirect German and Spanish traffic to thous 4 pages too the NEW.htm as well?

In my research I've read about people talking about {HTTP_ACCEPT_LANGUAGE} and {HTTP:Accept-Language} and {HTTP_HOST} for doing this correctly. I think some one wrote that {HTTP:Accept-Language} is the best solution. And on another place I read that one should use both {HTTP:Accept-Language} and {HTTP_HOST}. But I'm not sure how to put this together.

I'm not sure if this is right (probably not), but this is how far I've come:

* Regarding {HTTP:Accept-Language}

# Redirect Spanish and German users
RewriteCond %{HTTP:Accept-Language} (de|es) [NC]
RewriteRule ^(PAGE1.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE2.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE3.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE4.htm)$ http://example.com/NEW.htm [R,L]

Or I could put in NC at the end (not sure why? Does NC mean chase sensitive?):

RewriteCond %{HTTP:Accept-Language} (de|es) [NC]
RewriteRule ^(PAGE1.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE2.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE3.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE4.htm)$ http://example.com/NEW.htm [R,NC,L]


* Regarding {HTTP_HOST}

# Not really sure what this is for
RewriteCond %{HTTP_HOST} (de|es)
RewriteRule ^(PAGE1.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE2.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE3.htm)$ http://example.com/NEW.htm [R,L]
RewriteRule ^(PAGE4.htm)$ http://example.com/NEW.htm [R,L]

Or should this one as well have the NC at the end?

RewriteRule ^(PAGE1.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE2.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE3.htm)$ http://example.com/NEW.htm [R,NC,L]
RewriteRule ^(PAGE4.htm)$ http://example.com/NEW.htm [R,NC,L]


So, I was hoping someone in here could help me put together a working solution for redirecting all MSIE browsers and also all German and Spanish users/traffic as described here.

Thanks.

 

jdMorgan




msg:4318856
 12:06 am on May 28, 2011 (gmt 0)

After testing, you'll find that all requests for "PAGE2" through "PAGE4" are 302-redirected to NEW.htm.

That's because a RewriteCond only applies to the first RewriteRule (singular) which follows it. Therefore, the other redirects are conditioned only by the requested URI, and the user-agent and language have no influence.

Another problem is that the Accept-Language header contains a prioritized list of language- and country-codes, and not necessarily only a single language entry. For example, its value might be:

Accept-Language: en-CA,fr-CA;q=0.9,en-GB,en-US;q=0.7,en,fr;q=0.5

This says that the person who configured the browser (Note Bien: Not necessarily the current user) prefers Canadian English or French, will be moderately happy with British or US English, and will accept any English or French as a last resort.

This was taken from the log of a US site receiving a presumably-Canadian visitor. You might well see the same thing with an English-Spanish mix from Caribbean countries or the Philippines, or perhaps an English-German mix from southern Africa, a French-German-Italian mix from Switzerland, etc.

So, the question really revolves around what the user wants, not what you want to give them based on the browser settings (be aware also of internet cafes, where the user has no control over the browser settings).

So, if it is possible, I strongly suggest that you simply *ask* the user what language they want. You can do this explicitly by providing the standard "row of tiny flags" at the top of the (or each) page which link to alternate-language versions of that page, or more indirectly -- say by providing different domains or sets of pages for different user-groups.

The latter method pretty much eliminates search ranking problems since a German user will search using German words and spellings, and your German page will almost certainly rank higher than your Spanish or Norsk page for that search. The same is true for your Spanish and Norsk pages...

Anyway, to fix and optimize your code for your current plan, you could use:

# 302 Redirect MSIE requests for all .htm pages except for NEW.htm itself to NEW.htm
RewriteCond %{REQUEST_URI} !^/NEW\.htm$
RewriteCond %{HTTP_USER_AGENT} ^([^\ ]+\ )+MSIE\ [0-9]+\.
RewriteRule \.htm$ http://www.example.com/NEW.htm [R=302,L]
#
# 302 Redirect requests having German or Spanish as the FIRST language
# preference for any of these four specific pages to NEW.htm
RewriteCond %{HTTP:Accept-Language} ^(de|es)([,;\-].+)?$ [NC]
RewriteRule ^(PAGE1|PAGE2|PAGE3|PAGE4)\.htm$ http://www.example.com/NEW.htm [R=302,L]

If you're not sure what [NC] means, then you've skipped the part between having the idea and coding: research. I suggest that a few hours spent studying the mod_rewrite documentation will almost certainly save you hours of frustration -- and maybe even save your site from getting knocked out of the search rankings; One little typo or coding or conceptual design error can do that. www.apache.org is your friend...

Jim

iliumx




msg:4318885
 2:10 am on May 28, 2011 (gmt 0)

Thank you very much for a long answer :-)

Thanks for explaining the language details to me. Well worth the read.
And I have a question about this. Even if my pages were written in English, Mexican or Swahili the users with browsers that have Spanish or German would still be redirected to NEW.htm, right? The language it self that is written on the page has nothing to say, only the users browser settings are the deciding factor for this {HTTP:Accept-Language} code, right?

But I have a question regarding the MSIE redirection part as well.
I have several other htm files in that folder. And I don't want MSIE users who arrive at these files to be redirected to NEW.htm, only the ones that land on PAGE 1 2 3 4 ... I only want thous 4 pages to be affected. How would the code look then? Should the line with REQUEST_URI be removed then? And perhaps add something I had done in my MSIE code?

Thanks so much for this help.

wilderness




msg:4318903
 4:04 am on May 28, 2011 (gmt 0)

But I have a question regarding the MSIE redirection part as well.
I have several other htm files in that folder. And I don't want MSIE users who arrive at these files to be redirected to NEW.htm, only the ones that land on PAGE 1 2 3 4 ... I only want thous 4 pages to be affected.


# preference for any of these four specific pages to NEW.htm

RewriteRule ^(PAGE1|PAGE2|PAGE3|PAGE4)\.htm$

iliumx




msg:4318991
 2:49 pm on May 28, 2011 (gmt 0)

Ok. Thank you very much. But I now have some changes.

* So how should this look if I were to redirect the MSIE traffic as follows:
PAGE1.htm to NEW1.htm
PAGE2.htm to NEW2.htm
PAGE3.htm to NEW3.htm
PAGE4.htm to NEW4.htm

Because the RewriteCond only applies to the first RewriteRule should I put in 4 RewriteCond lines,
and get rid of the {REQUEST_URI} line at the top since not all are going to get redirected to the same page?

RewriteCond %{HTTP_USER_AGENT} ^([^\ ]+\ )+MSIE\ [0-9]+\.
RewriteRule ^(PAGE1)\.htm$ http://www.example.com/NEW1.htm [R=302,L]
RewriteCond %{HTTP_USER_AGENT} ^([^\ ]+\ )+MSIE\ [0-9]+\.
RewriteRule ^(PAGE2)\.htm$ http://www.example.com/NEW2.htm [R=302,L]
RewriteCond %{HTTP_USER_AGENT} ^([^\ ]+\ )+MSIE\ [0-9]+\.
RewriteRule ^(PAGE3)\.htm$ http://www.example.com/NEW3.htm [R=302,L]
RewriteCond %{HTTP_USER_AGENT} ^([^\ ]+\ )+MSIE\ [0-9]+\.
RewriteRule ^(PAGE4)\.htm$ http://www.example.com/NEW4.htm [R=302,L]


* And the same goes for the {HTTP:Accept-Language} code, redirecting Spanish and German browsers as follows:
PAGE1.htm to NEW1.htm
PAGE2.htm to NEW2.htm
PAGE3.htm to NEW3.htm
PAGE4.htm to NEW4.htm

RewriteCond %{HTTP:Accept-Language} ^(de|es)([,;\-].+)?$ [NC]
RewriteRule ^(PAGE1)\.htm$ http://www.example.com/NEW1.htm [R=302,L]
RewriteCond %{HTTP:Accept-Language} ^(de|es)([,;\-].+)?$ [NC]
RewriteRule ^(PAGE2)\.htm$ http://www.example.com/NEW2.htm [R=302,L]
RewriteCond %{HTTP:Accept-Language} ^(de|es)([,;\-].+)?$ [NC]
RewriteRule ^(PAGE3)\.htm$ http://www.example.com/NEW3.htm [R=302,L]
RewriteCond %{HTTP:Accept-Language} ^(de|es)([,;\-].+)?$ [NC]
RewriteRule ^(PAGE4)\.htm$ http://www.example.com/NEW4.htm [R=302,L]


Thanks in advance.

wilderness




msg:4319003
 4:04 pm on May 28, 2011 (gmt 0)

Your making this way too complicated.

jdMorgan (Jim) is the expert here. His absence since late October has literally brought this forum to a halt.
Others (such as myself) are simply attempting to fill in the void and assist Jim during a period of which he has little time.

You should read very carefully was Jim has provided and NOT attempt to butcher his examples, rather modify them to your domain.

FWIW, if you desired different pages in your initial inquiry?
You should have designated same and NOT using the same page name.

lucy24




msg:4319009
 4:20 pm on May 28, 2011 (gmt 0)

You could save yourself a lot of aggravation if those were the actual filenames, because then all you'd have to do is redirect PAGE([1-4]) to NEW$1.

It would help to explain the real-life reasoning behind the language thing, because you could easily send people in unwanted directions. My own preferences for example-- set in the operating system and presumably handed down to all browsers (I only checked one)-- are:

HTTP_ACCEPT_LANGUAGE=iu,en-US;q=0.9,en;q=0.8,nb;q=0.7,nn;q=0.6,de;q=0.5,it;q=0.4,la;q=0.3,fr;q=0.2,es;q=0.1 I've actually got nine more on the master list, but the counter wouldn't go further. I have yet to see a www site written in la. Or, for that matter, iu.

Are you trying to reach only people whose first-choice language is de or es? What if they prefer Austrian or Swiss German? My OS offers both as separate options. Are they all being sent to the same German-and-Spanish ghetto?

To top things off, there is a-- stop me if you've heard this one-- relevant bug in MSIE 6 [webmasterworld.com] which we can only hope has now been fixed... and won't recur in later versions.

wilderness




msg:4319010
 4:24 pm on May 28, 2011 (gmt 0)

I've several times had help reading the webmasterworld.com posts


lucy,
FWIW, the above statement implies that English is NOT this person's primary language (i. e., they are using a translator)

Don

iliumx




msg:4319032
 6:05 pm on May 28, 2011 (gmt 0)

The reason for redirecting people that have their browser first language set to Spanish and German, preferably also thous that have Spanish or German as their second priority language (English-Spanish and a English-German mix),
is because I don't want them to see certain things on that page.
They will be redirected to another page that looks almost the same except for some banners that will be removed, and the text on that NEW page is also written in the same language (Swedish) as the PAGE they were redirected from,
but all of thous 4 pages are different in content...
I know this can trigger Googles duplicated content rule and that's why I have, for SEO purpose,
set the NEW-pages to be noindex and nofollow and also canonical pointing back to their respective PAGEs.
That's why I need Spanish and German users to be redirected from:

PAGE1.htm to NEW1.htm
PAGE2.htm to NEW2.htm
PAGE3.htm to NEW3.htm
PAGE4.htm to NEW4.htm

And also all MSIE users/browsers to do the same.
Reason for redirecting all MSIE users is because the MSIE-browser does not react or displayed correctly what I'm trying to achieve
(sorry, can't go into this more in detail, it's part of a product I'm suppose to launch in some months time).
Just trust me when I say it's not for illegal usage I want this htaccess rule in place.

In short: Redirect Spanish and German (first and second language mix) + redirect MSIE users.

lucy24




msg:4319136
 10:23 pm on May 28, 2011 (gmt 0)

the above statement implies that English is NOT this person's primary language

:P

OK, so you say rude things about Spaniards and Germans on your default page ;) This is fine. But extracting a language out of the Accept header is going to be a little bit messy.

For first-choice languages it is not a problem, as you've already seen:

RewriteCond %{HTTP:Accept-Language} ^(de|es) [NC]

(note the added ^ before the language pair). Since you're only looking at the very beginning of the language header, it doesn't matter if it's de-something or es-something.

Taking it to a second choice is trickier. You need to exclude German, Spanish and (I assume) Swedish from the beginning of your search, and then proceed to the second language, if there is one.

Look again at the beginning of my own language header.

HTTP_ACCEPT_LANGUAGE=iu,en-US;q=0.9,en;q=0.8,nb;q=0.7,nn;q=0.6,de;q=0.5 ... et cetera

The very first language is in the standard [A-Za-z][A-Za-z] form. But no browser knows it, so www sites have to proceed to language #2, or rather language #0.9. This one's got a more complicated name, so you have to allow for
(-[A-Za-z][A-Za-z])?
(The [NC] will be useful later on, to accommodate visitors who use the CAPS LOCK too much, but I wouldn't rely on it here.)

I think this is what you want for the second choice.

RewriteCond %{HTTP:Accept-Language} ^!(de|es|se) [NC]
RewriteCond %{HTTP:Accept-Language} (de|es)(-[A-Za-z][A-Za-z])?;q=0\.9 [NC]

That's assuming the first number is always 0.9. If it isn't... Ugh.

Someone else will come along and tell you if it is safe to combine this with a SetEnvIf and %{ENV:blahblah} so you don't have to say the same thing five times in a row.

Oh, and I was serious about Page[1-4] going to New[1-4]. Not with those exact names, of course. But if you have a pattern like

/flottside : /flottark
/herrligside : /herrligark
/vidunderlegside : sorry, I'm making this up as I go along

et cetera, then you will be able to put everything into a single RewriteRule.

iliumx




msg:4322198
 1:47 pm on Jun 5, 2011 (gmt 0)

bump

wilderness




msg:4322200
 2:01 pm on Jun 5, 2011 (gmt 0)

Someone else will come along and tell you if it is safe to combine this with a SetEnvIf and %{ENV:blahblah} so you don't have to say the same thing five times in a row.


jdMorgan (Jim) is the expert here. His absence since late October has literally brought this forum to a halt.
Others (such as myself) are simply attempting to fill in the void and assist Jim during a period of which he has little time.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved