简单htaccess的重定向 - 子域文件夹 [英] Simple htaccess redirect - subdomain to folder

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

问题描述

我试图重定向HTTP:// [随机字符串] .domain.com /到http://domain.com/folder/ [随机字符串] /

I am trying to redirect http://[random-string].domain.com/ to http://domain.com/folder/[random-string]/

目前,我有这样的:

RewriteCond %{HTTP_HOST} ^.*\.domain\.com
RewriteRule ^.*$ http://domain.com/folder/$1/ [R=301,L]

目前,它指向 http://domain.com/folder// 。 ($ 1丢失)如何解决这个问题?

It currently points to http://domain.com/folder//. (The $1 is missing) How do I fix this?

推荐答案

您需要使用括号来获取价值相匹配,你的情况:

You need to use parenthesis to grab the value matched, in your case:

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

假设你也想重定向HTTP:// [随机字符串] .domain.com /东西http://domain.com/folder/[random-string]/something

assuming you also want to redirect http://[random-string].domain.com/something to http://domain.com/folder/[random-string]/something

这篇关于简单htaccess的重定向 - 子域文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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