我需要帮助,使用 .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 RewriteRule ^(.*)$ /subfolder/$1 [R=301]它几乎可以工作,但是当我在地址栏中输入 subdomain.domain 时,我被重定向到 subdomain.domain/subfolder/
It almost works, but when I enter subdomain.domain into the address bar, I get redirected to subdomain.domain/subfolder/
这真的很接近,但我不希望重定向 URL 中的前面的子域,我希望重定向转到 domain/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/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 RewriteRule ^(.*)$ domain/subfolder/$1 [R=301]应该可以.
更多推荐
如何使用 .htaccess 从子域重定向到子文件夹
发布评论