使用htaccess的子域目录重定向 [英] sub-domain directory redirection using htaccess

查看:175
本文介绍了使用htaccess的子域目录重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向这样的事情

sub-domain.domain.com/directory到domain.com/directory~~V

sub-domain.domain.com/directory to domain.com/directory

我试过重定向301 / domain.com/directory [htaccess的放置在子域文件]它工作正常子域名,但不会为子域内的目录工作。

I tried Redirect 301 / domain.com/directory [htaccess file placed in sub-domain] it works fine for the sub-domain but won't work for the directory within the sub-domain.

有人能帮我什么应该是.htaccess文件的内容?

Can somebody help me with what should be the content of .htaccess file ?

感谢。

推荐答案

如果您只是想从xxx.domain.com/yyy重新定向所有的请求www.domain.com/yyy~~V你可以使用:

If you simply want to re-direct all requests from xxx.domain.com/yyy to www.domain.com/yyy you can use:

RewriteCond %{HTTP_HOST}   !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.domain/com/$1 [L,R]

注意:您需要确保重写引擎是第一次,等

NB: You'll need to ensure that the rewrite engine is on first, etc.

更新..

如果你只是想要一个301,在最后一行更改[L,R] [L,R = 301]

If you just want a 301, change the [L,R] on the last line to [L,R=301]

这篇关于使用htaccess的子域目录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆