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

编程入门 行业动态 更新时间:2024-10-22 07:17:59
本文介绍了如何使用 .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 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 从子域重定向到子文件夹

本文发布于:2023-10-31 13:03:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546165.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文件夹   重定向   从子   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!