将具有URL的域重定向到具有URL的子域

时间:2019-03-13 14:34:58

标签: php .htaccess redirect

我想将https://www.domain.rs重定向到https://mysite.domain.rs并将https://www.mysite.rs/this_is_some_page.html重定向到https://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.在/之后继续。我希望将其重定向到从https://www.domain.rs/this_is_my_page.phphttps://mysite.domain.rs/this_is_my_page.php

输入的U. R.

有帮助吗?

1 个答案:

答案 0 :(得分:2)

此行:

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是您要重写的位置,因此此regex ^(.*)$将是由$1提出。

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

相关问题