Forum Moderators: phranque

Message Too Old, No Replies

httaccess conditional redirect

         

tripol

5:24 pm on Jun 22, 2010 (gmt 0)

10+ Year Member



I have such code:

RewriteEngine On
RewriteCond %{HTTP_ACCEPT_LANGUAGE} en
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ [%{HTTP_HOST}...]

But it is not working. What is wrong?

tripol

5:26 pm on Jun 22, 2010 (gmt 0)

10+ Year Member



It look like this:

RewriteEngine On
RewriteCond %{HTTP_ACCEPT} en
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ http://%{HTTP_HOST}/index_en.php

g1smd

6:12 pm on Jun 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It isn't "working" because it is "broken".

In order to proceed...

What was it meant to do?

What was the test URL? (Use
example.com
here)

What did it actually do?

How did that differ from what you wanted?

Always
# Comment your code
so you know what each bit does.


It looks like it might be a 302 redirect of some kind.

tripol

6:52 pm on Jun 22, 2010 (gmt 0)

10+ Year Member



I wan't to redirect users from which HTTP_ACCEPT_LANGUAGE header contains 'en'. And which accessed to the root of the server. But I know that mod_rewrite don't support HTTP_ACCEPT_LANGUAGE header. So I think that it is impossible to make this in .httaccess file. So now I am looking to php's usage of header('Location: #*$!xx')

jdMorgan

8:50 pm on Jun 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> mod_rewrite don't support HTTP_ACCEPT_LANGUAGE

Actually, mod_rewrite supports *all* possible HTTP headers, even customized ones that you create yourself. But the names for non-native variables are different:

RewriteCond %{HTTP:Accept-Language} ^([^,]+,\ ?})*en([-,;].*)?$
RewriteRule ^$ http://%{HTTP_HOST}/index_en.php [R=303,L]

The 'fancy stuff' on the language pattern prevents mis-matches and acceptance of badly-formatted language headers. It requires that any character preceding "en" must be a comma or a space, and that any character following "en" must be a hyphen, a comma, or a semi-colon, in accordance with the rules for 'building' correct Accept-Language headers.

Jim