开发者

How to rewrite urls on a multilingual website, with different domain names?

开发者 https://www.devze.com 2023-02-11 06:10 出处:网络
I\'ve made an international website where languages are available like this : www.sitename.com/es/spanishpage.html

I've made an international website where languages are available like this :

www.sitename.com/es/spanishpage.html

www.sitename.com/de/germanpage.html

www.sitename.com/fr/frenchpage.html

...

All lang folders are virtual, so i can make hundreds versions with the same number of PHP pages. To do so 开发者_运维技巧i use rewrite rules to create the pages, something similar to this :

RewriteRule ^germanpage\.html$ /page.php?lang=de [L]

Now i'd like to use real domain names. How can i do that please ? I think I have to create physical folders (de/, /fr/ ...) for domains, but then how i rewrite the pages?

I mean, sitename.de/ goes to myserver.com/de/ . It works, but it's an empty folder. How can i redirect all the website to my pages located at myserver.com/page.php?lang=de please ?

Thanks a lot for you help ! I'm really lost.

nb. don't know if it's iportant, but the site is running on a dedicated server.


The answer I found consist in setting all the domains under the server root, and then simply put redirects without the virtual folders.

so for mydomain.com/de/germanpage.html

This rule :

RewriteRule ^de/germanpage\.html$ page.php?lang=de

Becomes :

RewriteRule ^germanpage\.html$ page.php?lang=de

There must an easier solution (because now i can't have .de/contact.html and .fr/contact.html) but at least it works.


you can use soft links instead of creating physical folders. Click here to find out more about Symbolic link

Go to root folder at your domain (let say you have index.php in your root folder) myserver.com

now execute following commands

ln -s es
ln -s de
ln -s fr

now if you access http://myserver.com/fr/index.php file that will be executed is http://myserver.com/index.php

0

精彩评论

暂无评论...
验证码 换一张
取 消