如何使用 .htaccess 从子域重定向到子文件夹 [英] How to redirect from a subdomain to a subfolder using .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 文件中,我有以下代码:
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 中的前面的子域,我希望重定向转到 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/
推荐答案
您需要更改 RewriteRule 以包含您尝试重定向的新域,否则它将处理开头的 /
作为当前域上的新路径.
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]
应该可以.
这篇关于如何使用 .htaccess 从子域重定向到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!