问题原文
原帖链接 · Dtheme · CC BY-SA 4.0
I've an old subdomain that was being used as a whitelabel.
I'd like to redirect the subdomain to a page on my main domain.
I was thinking the best way would be a htaccess redirect.
RewriteCond %{HTTP_HOST} ^mysubdomain\.example\.com$ [NC]
RewriteRule ^(.*) https://www.example.com/newpage.html/$1 [L,R]
I've a feeling the above rewrite is not correct.
I've also got another redirect in my htaccess for the main domain so I'm not sure where to put this in?
Finally, is there another way of doing this?
已采纳解答
原帖链接 · closetnoc · CC BY-SA 4.0
You are close.
RewriteCond %{HTTP_HOST} ^sub-domain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/newpage.html [R=301,L]
--or--
RewriteCond %{HTTP_HOST} ^sub-domain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/folder/ [R=301,L]
I included the second example in case you want it.
I also use R=301,L. R,L is nearly the same thing defaulting to a 302 redirect which is temporary whereas a 301 is permanent. A 301 is what you want. I like to be explicit when using R.
Notice I use both the ^ and $ to properly define the beginning and end of any regex (regular expression). I have learned to avoid misinterpretation where possible. Again, I like to be explicit.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
