drupal 多站点 htaccess:将一个子站点上的所有语言重写为默认语言
我有一个 Drupal 6 多站点,有 2 个域(www.example.com 和 www.domain.com),共享一些常见内容。
域名 example.com 使用三种语言(EN、FR、NL)。语言由路径前缀(/en、/fr、/nl)设置。另一个域domain.com 仅使用一种语言(NL)。
问题:在很多情况下,即使没有填写路径前缀,domain.com 也会以错误的语言显示。不知何故,它似乎默认为 EN,尽管并非总是如此那 - 行为似乎不太一致。
解决方案(至少我希望):因为我不是 Drupal 开发人员(我从前同事那里继承了该网站),所以我不知道如何在 Drupal 中解决这个问题,所以我我认为解决这个问题的最佳方法是向 .htaccess 添加一些重写规则。
我也不是 htaccess/regex 专家,并且无法让它工作。您可以在下面找到我当前的重写规则,非常欢迎任何帮助或建议。
一些例子:
www.domain.com/fr/some-title
需要重写为www.domain.com/nl/some-title
www.domain.com/node/1975
需要重写为www.domain.com/nl/node/1975
这些是已经存在的重写规则:
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
我尝试添加这:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^/(.*)$ /nl/$1
并希望这只是为了将 /nl/ 添加到所有路径(因此不是完整的解决方案,因为 /fr/some-title
将变为 /nl/fr/some-title
) - 但是,快速测试表明:
/fr/some-title
被重写为/nl/some-title
(这是我需要的,但不是我期望的)/some-title
不是重写问题:有什么想法可能是错误的吗?或者这可能是由其他(Drupal)设置引起的?或者有更好的方法来解决我的问题吗?
为了完整起见:实时网站是 www.cinemazuid.be
I have a Drupal 6 multisite, with 2 domains (www.example.com and www.domain.com), sharing some common content.
The domain example.com is in three languages (EN, FR, NL). Languages are set by path prefix (/en, /fr, /nl). The other domain domain.com is just in one language (NL).
The problem: on many occasions domain.com is shown in the wrong language, even if no path prefix is filled in. Somehow it seems to default to EN, though it doesn't always do that - behaviour doesn't seem to be very consistent.
The solution (at least I hope): since I'm not a Drupal developer (I inhereted the site from a former colleague) I have no idea how to fix this in Drupal, so I thought the best way to fix it would be to add some rewrite rules to .htaccess.
I'm no htaccess/regex expert either, and can't get it working. You can find my current rewrite rules below, any help or suggestions are most welcome.
Some examples:
www.domain.com/fr/some-title
needs to be rewritten towww.domain.com/nl/some-title
www.domain.com/node/1975
needs to be rewritten towww.domain.com/nl/node/1975
These are the rewrite rules that were already there:
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I tried adding this:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^/(.*)$ /nl/$1
and would expect this just to prepend /nl/ to all paths (thus not being a full solution since /fr/some-title
would become /nl/fr/some-title
) - however, a quick test shows me that:
/fr/some-title
is rewritten to/nl/some-title
(which is what I need, but not what I expected)/some-title
is not rewrittenThe question: any ideas what might be wrong? Or could this be caused by other (Drupal) settings? Or is there a better way to solve my problem?
Just for the sake of completeness: the live website is www.cinemazuid.be
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这个规则
在您的 .htaccess 文件中,我很惊讶它的工作原理,因为前导
/
总是被删除,所以理论上它应该永远不会匹配任何请求。如果您希望对未指定语言的请求强制使用默认语言 NL,请将以下规则添加到 .htaccess 文件的顶部,位于任何现有规则之前
。想要重定向,只需删除
我在上面编辑的代码,将
/fr/some-title
替换为/nl/some-title/
>。L 标志告诉 mod_rewrite 停止处理进一步的规则,这通常是您想要的,除非您有另一个规则需要进一步处理当前请求。
If this rule
is in your .htaccess file, I am surprised that it works as the leading
/
is always stripped out, so it should theoretically never match any request.If your desire is to force a default language of NL for those requests that do not specify a language, then add the following rules to the top of your .htaccess file, before any existing rules
If you do not want to redirect, just drop the
R=301
I edited code above to replace
/fr/some-title
with/nl/some-title/
.The L flag tells mod_rewrite to stop processing further rules, which is usually what you want, unless you have another rule that needs to further process the current request.