Harrttie
Harrttie

Reputation: 1

How to change language url to clean URL with htaccess

I would like to use Clean URL htaccess on my website

it's important URLs for SEO, How can I change my URL from

http://www.mysite.com/?do=change&lang=en  to  http://www.mysite.com/en/

File functions.php

include './lang/choose.lang.php';

function Browser_Lang(){
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
switch ($lang){
    case 'ar': // Arabic
        return 'ar';
        break;
    default:   // English for other languages
        return 'en';
        break;
}
}

File choose.lang.php

if($_REQUEST['do'] == 'change'){
$lang = Secure($_GET['lang']);
Set_Cookie('language',$lang,time()+(3600*24*30*12));
}
if(isset($_COOKIE['language'])){
    $lang = Read_Cookie('language');
}else if(!isset($_COOKIE['language']) && isset($_SERVER['REMOTE_ADDR'])){
    $lang = Browser_Lang();
}else{
    $lang = 'en';
}

switch ($lang){
    case 'ar': // Arabic
        include 'ar.lang.php';
        break;
    default:   // English for other languages
        include 'en.lang.php';
        break;
}

Upvotes: 0

Views: 1796

Answers (3)

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

To redirect from http://www.mysite.com/?do=change&lang=en to http://www.mysite.com/en/, you must capture the query string argument lang with RewriteCond and insert that into the RewriteRule

RewriteCond %{QUERY_STRING} lang=(.+)
RewriteRule ^$ /%1/ [R,L]

Upvotes: 0

Avin Varghese
Avin Varghese

Reputation: 4370

Rewrite rule:

RewriteEngine On
RewriteRule ^([^/]*)/$ /?do=change&lang=$1 [L]

Upvotes: 0

David 10K
David 10K

Reputation: 303

You want to know the rewrite rule in .htaccess? This could be sth like this:

RewriteRule ^(en|ar)/?$ /?do=change&lang=$1 [L]

Upvotes: 1

Related Questions