用htaccess将文件夹重写到子域 [英] Rewrite folder to subdomain with htaccess

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

问题描述

此后我要重写所有地址

http://example.com/users/*

对此

http://*.example.com/

例如:

http://example.com/users/admin

http://admin.example.com/

我想在.htaccess文件中执行此操作.

I want to do this in a .htaccess file.

我现在有这个,但是它不起作用:

I now have this, but it dont work:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]

有人可以帮助我吗?谢谢

Can anyone help me? Thanks

推荐答案

删除RewriteCond中域之前的点:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]

您的规则失败,因为您要对照http://example.com进行检查,而不是与起始点不匹配.

Your rule is failing because you are checking against http://example.com, not matching the starting dot.

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

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