Vasil Dakov
Vasil Dakov

Reputation: 2039

WordPress and .htaccess

I have a website powered by WordPress MU. The front page of the site is translated in several languages. How do I rewrite the following URLs?

http://www.example.com/?lang=en
http://www.example.com/?lang=fr

to:

http://www.example.com/en/
http://www.example.com/fr/

This is my current .htaccess,

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# Uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress

Upvotes: 0

Views: 438

Answers (3)

RageZ
RageZ

Reputation: 27313

I have not tested so I am not 100 % sure if it works but that should give you some ideas.

I advice you to take a look at the documentation of mod-rewrite.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

#languages
RewriteRule ^/(en|fr)/(.*)$ /$2?lang=$1

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress

Upvotes: 3

Pradeep Singh
Pradeep Singh

Reputation: 3634

RewriteEngine On
RewriteBase /

RewriteRule ^en  /?lang=en
RewriteRule ^fr  /?lang=fr

Upvotes: 1

Linus Kleen
Linus Kleen

Reputation: 34612

This will redirect and preserve the original query string:

RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^([a-z]{2}) /?lang=$1&%1 [L]

RewriteRule ^([a-z]{2}) /?lang=$1 [L]

Upvotes: 2

Related Questions