0

I have three different domains pointing to the same WordPress's host instance depending on the language (managed with the qTranslate plugin):

RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.cat$
RewriteRule ^/?$ "http\:\/\/ca\.mydomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteRule ^/?$ "http\:\/\/en\.mydomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.es$
RewriteRule ^/?$ "http\:\/\/es\.mydomain\.com\/" [R=301,L]

With that I've managed to achieve the following redirects:

  • mydomain.cat or www.mydomain.cat ---> ca.mydomain.com ---> Shows website in catalan
  • mydomain.es or www.mydomain.es ---> es.mydomain.com ---> Shows website in spanish
  • mydomain.com or www.mydomain.com ---> en.mydomain.com ---> Shows website in english

Now the trouble I have is that, for example, user types mydomain.cat/work it doesn't works fine, it goes to mydomain.com/work/ and the language part in the subdomain is missing. It would be perfect if, in that case, it redirects to ca.mydomain.com/work.

I've researched and tried to modify the three RewriteCond rules to "add" the additional content at the end of the url (don't know if is better with QUERY_STRING or with parameters) if it exists, but I couldn't get it working fine, rather I don't know if it's the best way to achieve it.

Anyone can help me or give me a clue?

4

1 に答える 1

0

わかりました、私はそれを働かせました:

RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.cat$
RewriteRule (.*) "http\:\/\/ca\.mydomain\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteRule (.*) "http\:\/\/en\.mydomain\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.es$
RewriteRule (.*) "http\:\/\/es\.mydomain\.com\/$1" [R=301,L]

RewriteRule ステートメントの末尾に $1 を追加し、先頭の ^/?$ を (.*) で上書きしました。また、次の 2 行を他の行の上に追加しました。

RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

末尾のスラッシュを防ぐため。これが誰かの役に立てば幸いです。

于 2012-09-24T13:34:49.547 に答える