htaccess的子域名重定向 [英] htaccess subdomain redirect

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

问题描述

我已搜索周围,尝试了几种不同的方式,但不能得到这个工作。

I've searched around and tried a few different ways but can't get this to work.

我其实没有设立子域,但有我需要做的约30类似的重定向。

I don't actually have the subdomains set up, but will have about 30 similar redirects that I need to do.

例如:

sub-domain.domain.co.uk需要去 HTTP://www.domain .COM /文件夹/页名

sub-domain.domain.co.uk needs to go to http://www.domain.com/folder/page-name

将有几乎每一个子域,每一个页面名'连字符,所以我不知道这是否会影响正则表达式的格式。

There will be hyphens in almost every subdomain and every 'page-name', so I'm not sure if this affects the regex formatting.

任何帮助将是非常美联社preciated!

Any help would be much appreciated!

感谢

推荐答案

您需要使用%{HTTP_HOST}变量并匹配在一个RewriteCond指令,然后用%1反向引用来访问它重写规则。

You need to use the %{HTTP_HOST} variable and match it in a RewriteCond, then use a %1 backreference to access it in a rewrite rule.

搜索子域名重定向对堆栈溢出,它看起来像这正是你想要的:的内部子域夹重定向

Searching for "subdomain redirect" on Stack Overflow, it looks like this is exactly what you want: Internal subdomain to folder redirect

修改

在上面的计算器链接接受的答案:

The accepted answer in that StackOverflow link above:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$ 
RewriteRule ^ %1%{REQUEST_URI} [L]

在你的.htaccess文件,把那上面的任何规则,你有。很显然,你将需要修改例如\ .COM 来无论你的域名,并在您的文档根目录正确的目录设置。

In your .htaccess file, put that above whatever rules you have. Obviously, you're going to need to modify example\.com to whatever your domain is, and have the proper directories setup in your document root.

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

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