【问题标题】:Redirect based on part of filepath to new domain with .htaccess?使用.htaccess 基于部分文件路径重定向到新域?
【发布时间】:2015-04-10 14:03:30
【问题描述】:

我正在尝试确定我的 .htaccess 应该如何执行以下操作:

获取任何看起来像的网址

{协议}thedomain.co.uk/home/{其余 uri}

{协议}www.thedomain.co.uk/home/{其余的uri}

重定向到

{协议}subdomain.thedomain.co.uk/home/{rest of uri}

应该很简单,但我拥有 5 岁孩子的正则表达式技能。任何帮助表示赞赏。

【问题讨论】:

    标签: php regex apache .htaccess redirect


    【解决方案1】:

    将此添加到站点根目录的 .htaccess 文件中。

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(www\.)?thedomain\.co\.uk [NC]
    RewriteCond %{HTTPS}s ^on(s)|off 
    RewriteRule ^(home/.*)$ http%1://subdomain.thedomain.co.uk/$1 [R=301,L]
    

    【讨论】:

    • 只是一个简单的问题,如果 url 是 thedomain.co.uk/home 它而不是 thedomain.co.uk/home/ 它也被重定向,我该如何做呢?跨度>
    • 改用RewriteRule ^(home(/.*)?)$
    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    相关资源
    最近更新 更多