?
Solved

htaccess RewriteRule using domain name for language as a parameter.

Posted on 2010-08-16
3
Medium Priority
?
623 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 2000 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

800 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