【问题标题】:Redirect Domain with URL to Subdomain with URL将带有 URL 的域重定向到带有 URL 的子域
【发布时间】:2019-03-13 14:34:58
【问题描述】:

我想将 https://www.domain.rs 重定向到 https://mysite.domain.rshttps://www.mysite.rs/this_is_some_page.htmlhttps://mysite.domain.rs/this_is_some_page.html... 我该怎么做?

我试过这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.rs$ [NC]
RewriteRule ^(.*)$ https://mysite.domain.rs/ [L,R=302]

但这只会将我重定向到https://mysite.domain.rs,无论 U.R.L. 在 / 之后继续什么。我希望它被重定向到任何 U.R.L. 输入为 https://www.domain.rs/this_is_my_page.phphttps://mysite.domain.rs/this_is_my_page.php

有什么帮助吗?

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    这一行:

    RewriteRule ^(.*)$ https://mysite.domain.rs/ [L,R=302]
    

    应该是:

    RewriteRule ^(.*)$ https://mysite.domain.rs/$1 [L,R=302]
    

    这个 pasrt ^(.*)$ pattren(Regex) 是为了匹配当前请求的 URI,替换 https://mysite.domain.rs/$1 是你想要重写的位置,所以这个正则表达式 ^(.*)$ 将由 $1 呈现。

    清除浏览器缓存然后测试是否一切正常,将[L,R=302]更改为[L,R=301]为永久重定向。

    【讨论】:

      猜你喜欢
      • 2023-02-23
      • 2014-12-04
      • 2019-08-25
      • 1970-01-01
      • 2019-05-28
      • 2019-12-10
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多