几个小时后,我需要帮助。我尝试重写使用通配符子域的url。
我的域名将是*.domain.com -例如mytest.domain.com
每个子域都有一个位于www.domain.com/sdom/content/mytest下的子文件夹
我已经设置了apache/nginx服务器。为了进行测试,我在"content“文件夹中上传了一个index.html。
如果我键入mytest.comain.com,将显示此index.html。所以现在我上传了这个文件夹中的.htaccess文件,以便从这里路由到目的地(在本例中是"mytest“文件夹)。
我试过很多方法,至少这个
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule (.*) /httpdocs/domain/sdom/content/$1/index.html我调用了mytest.domain.com,但它不会转到子文件夹,它会转到主域。
如果我删除htaccess文件,将显示"content“文件夹的index.html。
在重写浏览器地址字段中的url后,应该显示mytest.domain.com,而不是子文件夹的新路径等。
我要做的就是工作吗?
更新
子域路由到->主文件夹子域名应通过htaccess路由到与子域同名的文件夹
所以我试了一试
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld$
RewriteRule ^$ /subdomainfolder/index.html发布于 2019-01-08 00:32:49
使用.htaccess文件就不能了,这里的mytest.domain.com和www.domain.com是不同的主机名。因此不可避免地会发生外部重定向。
如果您希望不同的域由一台物理服务器运行,则应使用虚拟主机:
<VirtualHost *:80> # Change this to *:443 if you use SSL/TLS
ServerName mytest.domain.com # Your domain name
DocumentRoot $SRV_ROOT/httpdocs/domain/sdom/content/mytest/ # assuming $SRV_ROOT is set to root of your server
<Directory "$SRV_ROOT/httpdocs/domain/sdom/content/mytest/">
Require all granted # on Apache 2.4
# Below are instructions for Apache 2.2
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>每次添加子域时,您都需要重新启动服务器,如果您在本地测试,还需要在/etc/hosts文件中保存DNS记录或本地记录。
https://stackoverflow.com/questions/54076582
复制相似问题