[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

htaccess RewriteRule using domain name for language as a parameter.

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

656 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