如何从一个子域使用的.htaccess重定向到子文件夹 [英] How to redirect from a subdomain to a subfolder using .htaccess

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

问题描述

我需要帮助重定向一个子域到子文件夹使用.htaccess文件我的网站。我不是关于一个亲配置.htaccess文件,所以请原谅我,如果我的问题是一个简单的解决方法。

I need help redirecting a subdomain to a subfolder on my website using the .htaccess file. I am not a pro in regards to configuring the .htaccess file, so please forgive me if my problem is a simple fix.

在我的.htaccess文件,我有以下code:

In my .htaccess file, I have the following code:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com  
RewriteRule ^(.*)$ /subfolder/$1 [R=301]

这几乎是工作,但是当我进入 subdomain.domain.com 到地址栏,我得到重定向到 subdomain.domain.com/subfolder /

It almost works, but when I enter subdomain.domain.com into the address bar, I get redirected to subdomain.domain.com/subfolder/

这是非常接近的,但我不希望重定向的URL的preceding子域,我想重定向到转至 domain.com/subfolder /

This is really close, but I don't want the preceding subdomain in the redirected URL, I want the redirection to go to domain.com/subfolder/

推荐答案

您需要改变你的重写规则,包括你想重定向过的新领域,否则会将开始 / 作为当前域的新路径。

You need to change your RewriteRule to include the new domain you're trying to redirect too, otherwise it will treat the beginning / as a new path on the current domain.

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com
RewriteRule ^(.*)$ http://domain.com/subfolder/$1 [R=301]

应该做的伎俩。

Should do the trick.

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

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