htaccess 子域重定向
我四处搜寻并尝试了几种不同的方法,但无法使其发挥作用。
我实际上没有设置子域,但需要执行大约 30 个类似的重定向。
例如:
sub-domain.domain.co.uk 需要转到 http://www.domain。 com/folder/page-name
几乎每个子域和每个“页面名称”中都会有连字符,所以我不确定这是否会影响正则表达式格式。
任何帮助将不胜感激!
谢谢
I've searched around and tried a few different ways but can't get this to work.
I don't actually have the subdomains set up, but will have about 30 similar redirects that I need to do.
E.g:
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.
Any help would be much appreciated!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 %{HTTP_HOST} 变量并在 RewriteCond 中匹配它,然后使用 %1 反向引用在重写规则中访问它。
在 Stack Overflow 上搜索“子域重定向”,看起来这正是您想要的: 内部子域到文件夹重定向
编辑
上面 StackOverflow 链接中接受的答案:
在您的 .htaccess 文件中,将其放在您拥有的任何规则之上。显然,您需要将
example\.com
修改为您的域,并在文档根目录中设置正确的目录。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
EDIT
The accepted answer in that StackOverflow link above:
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.