php - 使用 .htaccess 根据文件路径的一部分重定向到新域?

标签 php regex apache .htaccess redirect

我正在尝试弄清楚我的 .htaccess 应该是什么样子来执行以下操作:

获取任何看起来像

的网址

{the protocol}thedomain.co.uk/home/{rest of uri}

或者

{the protocol}www.thedomain.co.uk/home/{rest of uri}

重定向到

{the protocol}subdomain.thedomain.co.uk/home/{rest of uri}

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

最佳答案

将其添加到站点根目录的 .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]

关于php - 使用 .htaccess 根据文件路径的一部分重定向到新域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28433373/

相关文章:

php - Zend Framework 2 和 Doctrine 2 - 多个数据库的配置

php - 如何只从多部分电子邮件中获取文本内容?

javascript - JavaScript 中正则表达式模式的否定

php - 什么取决于何时在特定的 "composition"中考虑字符?

python - Apache 上的 Django 网站,wsgi 失败

apache - Htaccess 将 http 或 https 从 domain.com 重定向到 https domain.net

php - 哈希函数在ColdFusion 10+和PHP 7.x上的功能相同吗?

php - SHA256 盐与 PHP 和 MySQL - 插入错误

regex - 找到正则表达式 (a|b)*ab(a|b)* 的补码

c# - HttpWebResponse 不会针对并发出站请求进行扩展