【问题标题】:Redirect URLs from many subdomains using .htaccess使用 .htaccess 从许多子域重定向 URL
【发布时间】:2019-02-11 12:04:07
【问题描述】:

我正在更改我的网站结构,我需要从许多子域重定向 301 多个 URL。 我有很多子域,我怎样才能在一个 .htaccess 中做到这一点? 重定向两者:

ch.mydomain.com/coffeewww.mydomain.com/de_ch/coffee

it.mydomain.com/coffeewww,mydomain.com/it_IT/coffee

编辑: 有些 URL 有文件夹,有些有不同的名称: 考试:

ch.mydomain.com/coffetype/nespressowww.mydomain.com/de_ch/nespressocafe

谢谢

【问题讨论】:

    标签: apache .htaccess url-rewriting dns subdomain


    【解决方案1】:

    您可以使用这些重定向规则:

    RewriteEngine On
    
    # specific rules
    RewriteCond %{HTTP_HOST} ^ch\. [NC]
    RewriteRule ^coffetype/nespresso/?$ http://example.com/de_ch/nespressocafe [L,NC,R=301]
    
    # generic rules that have same URIs after redirect
    
    RewriteCond %{HTTP_HOST} ^ch\. [NC]
    RewriteRule ^ http://example.com/de_ch%{REQUEST_URI} [L,NE,R=301]
    
    RewriteCond %{HTTP_HOST} ^it\. [NC]
    RewriteRule ^ http://example.com/it_IT%{REQUEST_URI} [L,NE,R=301]
    

    【讨论】:

    • 如果我有相同的页面名称,您的回答可能适合,但有时它会有所不同,有时会使用文件夹。所以我需要一个规则然后我会使用:Redirect 301 xxx yyy
    • 将特定规则放在通用规则之前。请参阅我的更新答案。
    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 2021-04-08
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 2010-11-22
    相关资源
    最近更新 更多