apache url为多语言站点重写

时间:2022-11-24 08:17:32

I'd like to achieve two goals using rewrite conditions under apache2 but this is not actually my cup of tea:

我想在apache2下使用重写条件实现两个目标,但实际上这不是我的一杯茶:

  • redirect mydomain.com to www.mydomain.com and this is pretty easy to do. I use:

    将mydomain.com重定向到www.mydomain.com,这很容易做到。我用:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

    RewriteCond%{HTTP_HOST}!^ www.example.com $ [NC]

    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

    RewriteRule ^(。*)$ http://www.example.com/$1 [L,R = 301]

  • redirect mydomain.es to www.mydomain.com/?lang=es (and so on for different languages)

    将mydomain.es重定向到www.mydomain.com/?lang=es(对于不同的语言,依此类推)

How can I write the second statement? And how can I combine this rule with the first one?

我怎么写第二个陈述?如何将此规则与第一个规则结合起来?

Thank you in advance for your help!

预先感谢您的帮助!

1 个解决方案

#1


0  

Try :

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^mydomain\.[^.]+$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^mydomain\.([^.]+)/(.*) http://www.mydomain.com/?lang=$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [L,R=301]

It's Ok for mydomain.es, mydomain.fr, mydomain.pt but it's no OK for www.mydomain.es

这对mydomain.es,mydomain.fr,mydomain.pt来说没问题,但对于www.mydomain.es来说还不行

#1


0  

Try :

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^mydomain\.[^.]+$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^mydomain\.([^.]+)/(.*) http://www.mydomain.com/?lang=$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [L,R=301]

It's Ok for mydomain.es, mydomain.fr, mydomain.pt but it's no OK for www.mydomain.es

这对mydomain.es,mydomain.fr,mydomain.pt来说没问题,但对于www.mydomain.es来说还不行