htaccess mod_rewrite .tld到特定文件夹

时间:2012-01-06 14:48:02

标签: .htaccess mod-rewrite tld

如果可能,我想用htaccess执行以下操作。

网页以这种方式工作,您通过domain.de/de/start获取索引文件,通过domain.de/en/start获取英文版本。

如果用户访问 domain.com ,我希望他以domain.de/en/而不是domain.de/de/结束,因此我需要重写所有对域的请求。 com 但不是domain.com/xx/somethingdomain.de/en/

的请求

感谢。

2 个答案:

答案 0 :(得分:3)

如果我清楚地了解您,您只想将http://domain.com/重定向到http://domain.de/en/,但 NOT 想要重定向http://domain.com/XX/YY

将此代码放入.htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^$ http://domain.de/en/ [L,R=301]

答案 1 :(得分:1)

尝试使用HTTP_HOSTrewritecond

RewriteCond %{HTTP_HOST}=domain.de
RewriteCond %{REQUEST_URI}=/              % redirect only the root
RewriteRule ^/$ /de/start [L]             % to /de/start

RewriteCond %{HTTP_HOST}=domain.de
RewriteCond !%{REQUEST_URI}=/             % no root
RewriteCond !%{REQUEST_URI}=/[a-z]{2}/.*  % except /xx/ directories
RewriteRule ^/.*$ /de/$1 [L]              % push the user in the /de/ directory
相关问题