如何从一个子域使用的.htaccess重定向到子文件夹个子、文件夹、重定向、htaccess

2023-09-02 11:25:55 作者:乳来伸掌

我需要帮助重定向一个子域到子文件夹使用.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.