apache - URI 重写到子域
问题描述
我尝试将 URI 更改为子域。如何更改www.domain.com/auth/signin
为login.domain.com
我有这样的虚拟主机:
<VirtualHost 127.0.0.5:80>
DocumentRoot "path/to/root/public"
ServerName domain.local
ServerAlias *.domain.local
</VirtualHost>
和.htaccess
RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
RewriteCond %{HTTP_HOST} !^domain.local
RewriteCond %{HTTP_HOST} ^(.+).domain.local
RewriteRule ^login/?$ http://domain.local/auth/signin [P,L,QSA]
解决方案
1:标准http版本:
RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
# If the url is not http://domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^domain\.local [NC]
# If the url is not http://www.domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^www\.domain\.local [NC]
# Redirect
RewriteRule ^login(.*)$ http://domain.local/auth/signin$1 [R=301,L,NC]
http://sub1.domain.local/login到http://domain.local/auth/signin
http://sub2.domain.local/login到http://domain.local/auth/signin
http://sub2.domain.local/login?token=1到http://domain.local/auth/signin?token=1
2:(可选)http或https检测
RewriteEngine On
php_flag display_errors 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
# If the url is not http(s)://domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^domain\.local [NC]
# If the url is not http(s)://www.domain.local (Added [NC])
RewriteCond %{HTTP_HOST} !^www\.domain\.local [NC]
# http or https detection
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS}:s on:(s)
# Redirect
RewriteRule ^login(.*)$ http%1://domain.local/auth/signin$1 [R=301,L,NC]
http://sub1.domain.local/login到http://domain.local/auth/signin
https://sub1.domain.local/login到https://domain.local/auth/signin
http://sub2.domain.local/login到http://domain.local/auth/signin
https://sub2.domain.local/login到https://domain.local/auth/signin
http://sub2.domain.local/login?token=1到http://domain.local/auth/signin?token=1
https://sub2.domain.local/login?token=1到https://domain.local/auth/signin?token=1
推荐阅读
- javascript - 使用 Azure JS SDK for Service Bus 时需要关闭连接吗?
- c++ - LNK1169 找到一个或多个多重定义的符号。我知道这可能被认为是重复的,但我找不到任何可以解决我的问题的东西
- r - 如何在 R 中的整个数据集中删除列中的重复值
- python - 当代码在循环上运行时,Python当前时间不会改变
- django - 我的查询返回一个 Id 而不是实际值
- amazon-web-services - 在 API 网关的 REST URI 中使用 base64 编码的路径参数
- json - Amchart 4 人口金字塔
- ios - DispatchQueue 和网络请求
- javascript - 在一种方法中动态创建剑道下拉菜单并在另一种方法中分配数据源
- java - 无法从数组中选择一个元素并将其分配给矩阵中的一个点