我找不到执行此永久重定向的方法: 从:
http://it.example.com/oldpath
到
http://www.example.com/it/newpath
“it”是语言id,它也可以是“fr”,“de”,“en”等。 我认为这可行:
RedirectMatch 301 http://(.*).example.com/oldpath/ http://www.example.com/$1/newpath/
但由于包含的路径,它无效。但删除它我失去了有关该语言的参数信息。如何进行这样的操作?
答案 0 :(得分:3)
您需要使用mod_rewrite而不是mod_alias来匹配主机名。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?!www)(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/%1/$1 [R=301,L]