htaccess redirect (multidomain multilanguage) subfolder wildcard

眉间皱痕 提交于 2019-12-25 03:39:15

问题


I have a typo3 installation with multidomain and multilanguage, where not every language is setup to every domain.

Languages are de/fr/en/pt/es/cn/

www.example.de can be de/en/fr but not
www.example.de pt/es/cn

now I have messed up sth. and google has indexed loads of wrong urls e.g.

www.example.de/pt/
www.example.de/es/
www.example.de/cn/

they point to languages that are not set for this domain

I am fiddling around in the htaccess to redirect 301 the wrong urls with wildcards(?) to the .tld

I am looking for a solution redirect eg.

www.example.de/pt/* to www.example.de/
www.example.de/es/* to www.example.de/
www.example.de/cn/* to www.example.de/

where the * should represent the complete sting/path following the language parameter.

and of cause the same procedure for the .com domain

www.example.com/fr/* to www.example.com/
www.example.com/de/* to www.example.com/

I searched the web up and down but nothing I tried works.
any help would highly apreciated.






a tiny step further

RewriteCond %{HTTP_HOST} ^www.example.de
RewriteRule ^cn/(.*)$ http://www.example.de/ [L,R=301]
RewriteRule ^pt/(.*)$ http://www.example.de/ [L,R=301]
RewriteRule ^es/(.*)$ http://www.example.de/ [L,R=301]

this seems to work

and now for the second domain as I need to differentiate between .com and .de

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^de/(.*)$ http://www.example.com/ [L,R=301]
RewriteRule ^fr/(.*)$ http://www.example.com/ [L,R=301]

this now breaks www.example.de/fr/whatever and redirects it to www.example.com as well.

so it looks like the first condition is matching and the the last rule is applied for french.

how can I limit the rules assigning them only to the appropriate domain conditions?


回答1:


ok looks like every condition and respective rule needs to be written in a single line an repeated

RewriteCond %{HTTP_HOST} ^www.example.de
RewriteRule ^cn/(.*)$ http://www.example.de/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example.de
RewriteRule ^pt/(.*)$ http://www.example.de/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example.de
RewriteRule ^es/(.*)$ http://www.example.de/ [L,R=301]

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^de/(.*)$ http://www.example.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^fr/(.*)$ http://www.example.com/ [L,R=301]

this seems to work.

any better solution is highly appreciated



来源:https://stackoverflow.com/questions/28627788/htaccess-redirect-multidomain-multilanguage-subfolder-wildcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!