Yet another .htaccess question

Hi all.

I want to have two languages on my website: english and german.

By doing this I am trying to pass two PHP variables between webpages: $page, and $lang.

I have been using this rewrite rule:

RewriteRule ^/(en|de)/([A-Za-z0-9]+)$ index.php?lang=$1&page=$2

but I cannot get it to work. A typical ‘a href’ link should then be something like “a href=”/en/news" or “a href=”…/en/news" in this case, right?

If I simply type in the variables in the URL like this:

?lang=de&page=news

it works fine and I can change the language to english by replacing “de” with “en” successfully and change the page variable easily.

However, I want a clean URL and would like to have:

example.com/de/news

instead where in this case “de” represents the ?lang value and “news” represents the ?page value.

If I put the .htaccess folder in the root folder, then I shouldn’t have to worry about subdirectories and the hierarchy of folders, correct?

PHP code:

<?php
if (!isset($_GET[‘page’])) {
$_GET[‘page’] = ‘home’;
}
$page = $_GET[‘page’];
?>
<?php
if (!isset($_GET[‘lang’])) {
$_GET[‘lang’] = ‘en’;
}
$lang = $_GET[‘lang’];
?>

My current folder directory is something like root->content->de->news.php

Sorry for the long post but I appreciate any help.

Look for MultiViews then change it’s setting to Options -MultiViews.

Regards,

DK

If I have a file named company.php in my localhost and browse to http://localhost/company/ the company.php takes precedence and is displayed. This is not true on my server though. I am thinking there is a setting in the httpd.conf to adjust this setting? It’s annoying and gets in the way of my .htaccess rewriting. I should get a page not found IMO if I did not correctly include the file extension in my URL.

Can anyone tell me where to change this setting?

Nevermind I got it working now.

I renamed my de.php and en.php files to deutsch.php and english.php. I had the $lang value the same as the .php files, which was why it wasn’t working. So in the future make sure your variables are not the same name as your .php files when rewriting. :slight_smile:
A newbie mistake.