2

I have this url's for multi language system using php :

http://mydomain/ <-- default language english (en)
http://mydomain/index.php?lang=de
http://mydomain/index.php?lang=fr
http://mydomain/index.php?lang=tr

Now, for another page i have this url:

http://mydomain/article.php?id=xx <-- show article details
http://mydomain/article.php?list=all  <-- show article archive
http://mydomain/gallery.php?id=xx
http://mydomain/faq.php?id=xx
http://mydomain/faq.php?list=all
http://mydomain/contact.php

Now, i need to create seo friendly url using php and htaccess Like This :

for index:

http://mydomain/  <-- for default
http://mydomain/de/
http://mydomain/fr/

for article ie:(domain/lang/id/title.html)

http://mydomain/de/articles/22/test.html

for page:

http://mydomain/de/contact.html

for archive:

http://mydomain/de/articles/listall.html

in htaccess i write this code for article :

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([0-9]+)/([A-Za-z0-9-]+)/?.html$ articles.php?id=$1

but this worked for one language not multiple language. how do can i create seo friendly url for multi language system?!

  • Can you clarify the last two sentences here? – dan Jan 20 '15 at 1:06
1

Try something like RewriteRule ^([en|es|ru|de]{2})/(.*)$ $2?lang=$1&%{QUERY_STRING} [L,QSA]

Where you'll want to replace [en|es|ru|de] with the all valid 2-letter language codes your site uses. This will then take whatever is after the language-code in the URL, and use that as the "main" URL, and then effectively append ?lang=es to the "actual" URL, though the user will not see this, it will happen in the background.

| improve this answer | |
  • this url not work for me: http://mydomain/es/news/2/ss.html – MeMoR Jan 21 '15 at 7:47
  • The rewrite I gave above will only handle 2 "parameters". The first for the language, the second for the filename. If you want to use an ID, you'll need to add a 3rd match (the parts in brackets). So if you want mydomain/de/news/2/ss.html to rewrite to mydomain/news.php?id=2&lang=de you'd need a rewrite like RewriteRule ^([en|es|ru|de]{2})/news/([0-9])/(.*) /news.php?id=$2&lang=$1 and then do that for each of your different URL structures (ie. articles, gallery, faq, etc. – nathangiesbrecht Jan 21 '15 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.