【问题标题】:Redirect to subdomain with condition check使用条件检查重定向到子域
【发布时间】:2016-07-20 06:57:32
【问题描述】:

我有一个域名:

example.com

带有子域:

blog.example.com

最初在主域而不是子域中处理的所有博客。但现在我已将它们移至文件夹“博客”。

以及之前的博客链接:

example.com/123/blogcontent1
example.com/458/blogcontent2
.......
.......
example.com/458/blogcontentn

我的问题是如何编写 htaccess 规则,这样,每当域 名称/“数字”附加将它们重定向到子域,如下所示 示例:

example.com/123/blogcontent1   ->  blog.example.com/123/blogcontent1
example.com/458/blogcontent2   ->  blog.example.com/458/blogcontent2

还有, 我已经检查了以下帖子,但它们不是有条件的,正如我的问题所述,

Redirect directory to a subdomain

How do I redirect domain to subdomain using htaccess?

如果有帮助的话会很有用。谢谢

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:

    您可以在example.com 的站点根目录.htaccess 中使用此规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
    RewriteRule ^\d+/ http://blog.example.com%{REQUEST_URI} [NE,R=301,L]
    

    【讨论】:

    • 但它与 blog.example.com 、 blog.example.com%7D/880/blogcontent1 一起占 %7d
    • 有一个额外的大括号导致 %7 谢谢 anubhava..
    • 非常感谢@utility 纠正我的拼写错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 2014-08-19
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多