Hi!

I have rewrite conditions in my htaccess but since I am using boost they are ignored. The function was that the user was redirected based on browser language. But now the default language is loaded regardless of the browser language.

My referred htaccess part:

 ### LANGUAGE NEGOTIOATION ###
  
  RewriteCond %{HTTP:Accept-Language} ^de [NC]
  RewriteRule ^$ /de [L,R=301]

  RewriteCond %{HTTP:Accept-Language} ^hu [NC]
  RewriteRule ^$ /hu [L,R=301]
  
  ### LANGUAGE NEGOTIOATION END ###


  ### BOOST START ###

  # Allow for alt paths to be set via htaccess rules; allows for cached variants (future mobile support)
  RewriteRule .* - [E=boostpath:normal]

  # Caching for anonymous users
  # Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request
  RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]
  RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add|comment/reply))|(/(edit|user|user/(login|password|register))$) [OR]
  RewriteCond %{HTTPS} on [OR]
  RewriteCond %{HTTP_COOKIE} DRUPAL_UID [OR]
  RewriteCond %{ENV:REDIRECT_STATUS} 200
  RewriteRule .* - [S=5]

  # GZIP
  RewriteCond %{HTTP:Accept-encoding} !gzip
  RewriteRule .* - [S=2]
  RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html\.gz -s
  RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html\.gz [L,T=text/html,E=no-gzip:1]
  RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.xml\.gz -s
  RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.xml\.gz [L,T=text/xml,E=no-gzip:1]

  # NORMAL
  RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
  RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
  RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.xml -s
  RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.xml [L,T=text/xml]

  ### BOOST END ###

Any help appreciated!

Comments

bgm’s picture

Status: Active » Fixed

I might be mistaking, but if I recall correctly, if you don't have a RewriteBase /, you should use "^/$" as your RewriteRule expression.

Ex:

  RewriteCond %{HTTP:Accept-Language} ^de [NC]
  RewriteRule ^/$ /de [L,R=301]

I tested locally, and ^$ didn't work for me either, ^/$ did. My boost rewriterules are in my Apache vhost.

If that works for you, could you document a snippet in the Boost 7.x-1.x handbook? (might be good to create a new sub-page specific to i18n tricks)

Thanks

hefterbrumi’s picture

Hi!

I used the same before (^$ ) but without boost and worked perfectly.

But thanks I will give it a try

No this doesnt work for me. I am sure that boost "overwrites" my rewrite rules. But I dont know how... I am on a shared server by the way

bgm’s picture

You can enable mod_rewrite debugging to see the trace of what is happening.

Boost doesn't do anything other than what it says in the htaccess. It's at the Apache level anyway. Hard to debug since I can't reproduce on a sandbox.

hefterbrumi’s picture

Ok I found out if I use it like this according to this method:

  RewriteCond %{HTTP:Accept-Language} ^hu.*$ [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /hu [L,R=302]

  RewriteCond %{HTTP:Accept-Language} ^de.*$ [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /de [L,R=302]

... it works. Please confirm and it can go to the handbook...

Anonymous’s picture

Hi, this issue was solved with caveats by mikeytown2 and others on this thread #768930: Drupal 6: Language fallback, browser detection but there are some side issues that should be read through, like some people getting stuck in one language side of the site forever. That was a version 6 thread which required some core code hacking.

However there are other solutions to the problem depending on the module being used for the language in particular this comment at the end #768930-28: Drupal 6: Language fallback, browser detection and this comment http://eureka.ykyuen.info/2011/06/19/drupal-force-path-prefix-for-defaul... by "outsourcer" changed one text box in D7 admin rather than hacking any code.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.