我有一个网站有三种语言和三个域名: cheese.org,fromage.org和kaese.org
我想创建以下重定向(使用通配符*)
cheese.org/fr/* redirects to fromage.org
cheese.org/de/* redirects to kaese.org
fromage.org/en/* redirects to cheese.org
fromage.org/de/* redirects to kaese.org
kaese.org/en/* redirects to cheese.org
kaese.org/fr/* redirects to fromage.org我摆弄了一下htaccess redirect (multidomain multilanguage) subfolder wildcard,但没有弄清楚。
有什么建议吗?
发布于 2019-03-14 00:43:56
看起来很直截了当。根据您需要重定向传入请求的http主机:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cheese\.org$ [OR]
RewriteCond %{HTTP_HOST} ^kaese\.org$
RewriteCond ^/?fr/(.*) https://fromage.org/$1 [R=301]
RewriteCond %{HTTP_HOST} ^fromage\.org$ [OR]
RewriteCond %{HTTP_HOST} ^kaese\.org$
RewriteCond ^/?en/(.*) https://cheese.org/$1 [R=301]
RewriteCond %{HTTP_HOST} ^cheese\.org$ [OR]
RewriteCond %{HTTP_HOST} ^fromage\.org$
RewriteCond ^/?de/(.*) https://kaese.org/$1 [R=301]此规则将在http服务器主机配置中或在动态配置文件(".htaccess“文件)中同样起作用。显然,需要在http服务器内部加载重写模块,并在http主机中启用该模块。在使用动态配置文件的情况下,您需要注意在主机配置中启用了它的解释,并且它位于主机的DOCUMENT_ROOT文件夹中。
还有一个一般性的注意事项:您应该始终倾向于将这样的规则放在http服务器主机配置中,而不是使用动态配置文件(".htaccess")。这些动态配置文件增加了复杂性,通常是导致意外行为的原因,难以调试,并且它们确实减慢了http服务器的速度。它们仅在您无法访问真实的http服务器主机配置(读作:真正便宜的服务提供商)或坚持编写自己的规则的应用程序(这是一个明显的安全噩梦)的情况下才被提供作为最后的选择。
https://stackoverflow.com/questions/55134961
复制相似问题