Solved

htaccess RewriteRule using domain name for language as a parameter.

Posted on 2010-08-16
3
609 Views
Last Modified: 2012-05-10
hi,
   Im managing a bilingual website.

Two languages can be used with URL like this.

www.website.com/product/computer.html?lang=en
www.website.com/product/computer.html?lang=jp
Also
www.website.com/product/apple/laptop.html?lang=en
www.website.com/product/apple/laptop.html?lang=jp


No other pages/url_patterns in the website needs Language settings.
I need a redirect rule to use with this 2 patterns with language in domain part of URL.

en.website.com/product/computer.html
should be processed internally as
www.website.com/product/computer.html?lang=en

and

jp.website.com/product/apple/laptop.html
should be processed as
www.website.com/product/apple/laptop.html?lang=jp

As you can see
domain part en/jp should become ?lang=en/jp
and should be valid with this URL patterns
xxxx/product/xxxxxx
AND
xxxx/product/apple/xxxxx

RewriteRule can be in httpd.conf OR htaccess.

Since Im not good at this RewriteRule I request you to have this as simple as possible.

Thank you for all in advance.

0
Comment
Question by:BToTheAToTheBABA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Assisted Solution

by:arober11
arober11 earned 500 total points
ID: 33447580
Try:

RewriteEngine On
RewriteCond %{QUERY_STRING}  !lang=[ej][np]  [NC]
RewriteCond %{REQUEST_URI}  ^/product/         [NC]
RewriteCond %{HTTP_HOST}      ^(en|jp)\.         [NC]
RewriteRule  .*   %{REQUEST_URI}?lang=%1      [L,QSA]
0
 

Author Comment

by:BToTheAToTheBABA
ID: 33519466
hi, This is working fine.

Can you explain these lines ?

RewriteCond %{QUERY_STRING}  !lang=[ej][np]  [NC]
RewriteCond %{REQUEST_URI}  ^/product/         [NC]
RewriteCond %{HTTP_HOST}      ^(en|jp)\.         [NC]
RewriteRule  .*   %{REQUEST_URI}?lang=%1      [L,QSA]
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 33525207
Sure:

# Turn on the Apache Rewrite Engine
RewriteEngine On    

# If the URL DOSE NOT contain a CGI-Parameter of "lang=XX", where XX is either {en, ep, jn, jp},  ignoring case (NC = NOT CASE sensitive)
RewriteCond %{QUERY_STRING}  !lang=[ej][np]  [NC]

# AND If the URL starts with "/Product/", in any case
RewriteCond %{REQUEST_URI}  ^/product/         [NC]

# AND If the URL starts with http://en.   or   http://jp.
RewriteCond %{HTTP_HOST}      ^(en|jp)\.         [NC]

# THEN Add (QSA = Query String Append) a "lang=XX" to the URL, and stop manipulating the URL (L = LAST rule)
RewriteRule  .*   %{REQUEST_URI}?lang=%1      [L,QSA]


See: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSH in linux 9 69
Increase counter and attr inside a while loop 15 37
Echo values after a query in php 5 26
Why is my implode function empty 8 18
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question