使用RewriteMap将域重定向到子域

问题描述 投票:0回答:1

我想使用RewriteMap将域重定向到map.txt中的子域

RewriteMap domainMap txt://path/to/map.txt

map.txt 内容:

exmple.com  mm.site.com
test.com    tt.site.com
domain.com  dd.site.com

我知道以下 htaccess 不正确,但它接近我想要的

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.site\.com$ [NC]
RewriteRule ^$ ${domainMap:%1} [L,R]


RewriteCond %{HTTP_HOST} !site\.com$ [NC]       
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+?)$          
RewriteCond %{REQUEST_FILENAME} !-f             
RewriteCond %{REQUEST_FILENAME} !-d         
RewriteRule (.*) /%1/$1 [L] 
php apache .htaccess subdomain
1个回答
0
投票

首先,检查您是否已将

RewriteMap
指令放入 Apache 配置中:

RewriteMap domainMap txt:/path/to/map.txt

你可以用这个

.htaccess
:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# Check if the domain is in the map and redirect
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond ${domainMap:%1} ^(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

© www.soinside.com 2019 - 2024. All rights reserved.