2

我在 Django 中创建了一个简单的站点。我使用的网址是 http::/www.example.com/nl/ 和http://www.example.com/fr/

我的 Django urls.py 有以下行:

(r'^(?Pnl|fr)/', 'example.views.index'),

在 example.views.index 我检查语言参数。如果它是“nl”,我会显示一个模板。如果它是“fr”,我会显示一个不同的模板。

这很好用。现在客户制作了两个不同的网址:

http://www.dutch.com/http://www.french.com/

最后我会问这个问题:

有没有办法让我在不更改我的 django 代码的情况下使用新的 url?我假设我可以告诉 apache在用户访问http://www.dutch.com/时显示http://www.example.com/nl/页面。但是我该怎么做呢?django 还能从 url 中获取“语言”参数吗?

提前感谢您的任何答案。

4

1 回答 1

2

如果您可以在http://www.dutch.com上使用 .htaccess 文件,您可以像这样使用 apache 的重定向指令

redirectMatch 301 ^(.*)$ http://www.example.com/nl/

这会将发送到 dutch.com 的所有请求重定向到 example.com/nl

你也可以使用

redirect 301 /index.html http://www.example.com/nl/

这只会将 dutch.com 上的“index.html”重定向到 example.com/nl/(请注意,第一个参数是路径,不能是 URL - 没有http://www

于 2009-03-18T10:52:53.600 回答