简体   繁体   English

htaccess子域301重定向

[英]htaccess subdomain 301 redirect

I've got what I considered to be a simple to fix issue where I want all the traffic from one subdomain redirected (301) to another subdomain (both on the same domain). 我有一个我认为很容易解决的问题,我希望将所有流量从一个子域重定向(301)到另一个子域(都在同一个域上)。

I've currently got this line in .htaccess 我目前在.htaccess中有这行

Redirect 301 news.domain.com blog.domain.com

but that throws a 500 error. 但这会引发500错误。

I'm totally lost with this and can't find any basic "this is how you redirect a to b" types of help. 我对此一无所知,找不到任何基本的“这就是将a重定向到b”的帮助类型。 Everything I've looked at seems really convoluted and massively overkill for what I believe to be such a simple task. 对于我认为如此简单的任务,我看过的所有内容似乎都感到费解和大刀阔斧。

Can someone help with this? 有人可以帮忙吗?

You can't match against the hostname/domain in the apache Redirect directive, you'll have to match against the %{HTTP_HOST} using a rewrite condition: 您无法使用apache Redirect指令中的主机名/域进行匹配,必须使用重写条件将其与%{HTTP_HOST}进行匹配:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^news\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://blog.domain.com/$1 [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM