.htaccess - 使用 htaccess 将文件夹重写为子域
问题描述
我想在此之后重写所有地址
http://example.com/users/*
对此
http://*.example.com/
例如:
http://example.com/users/admin
http://admin.example.com/
我想在 .htaccess 文件中执行此操作。
我现在有这个,但它不起作用:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]
谁能帮我?谢谢
解决方案
删除 中域之前的点RewriteCond
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]
您的规则失败,因为您正在检查http://example.com
,而不是匹配起始点。
推荐阅读
- xamarin - 如何确保我的 ListView 在 Xamarin 中刷新?
- intellij-idea - 我们如何使用 IntelliJ 输出图形?
- angular - ThemeSwitcher-使用primeng和Angular
- reactjs - 处理反应子级时,类型“元素 []”缺少以下属性
- sql - 在 Oracle APEX SQL 中将页面项与字符串进行比较
- google-sheets - 有没有办法将 Kaggle 中的数据导入 Google 表格?
- python - 俄罗斯方块从块中生成彩色形状
- python - 如何将完整的字符串输出转换为火炬张量
- python - 如何在 Python 和 ROS 中应用全局变量?
- c# - 传递给 File.ReadAllBytes 方法的文件路径被预先添加执行路径覆盖