【发布时间】:2019-01-09 01:01:57
【问题描述】:
我目前正在使用 PHP 开发一个基于 Web 的 SaaS 项目,该项目要求用户拥有唯一的子域才能使用该应用程序。
我已经完成了使用通配符配置服务器:例如。 user.example.com ==> *.example.com。应用程序在/var/www/html/ 下为用户创建一个子文件夹,其中包含用户名,例如。 user.example.com 将在 /var/www/html/user/ 中。
我坚持让没有基本文件夹(例如 user.example.com)的用户链接指向 /var/www/html/user/,而不必包含 http://user.example.com/user。
我尝试过虚拟主机和别名,但似乎我必须手动分配不适用于项目的变量。
我只需要子域指向它们各自的子文件夹。
我的 apache 配置文件
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin admin@xxxxxxx.tdl
DocumentRoot /var/www/html/%1/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ErrorDocument 404 /error_404.html
</VirtualHost>
【问题讨论】:
-
stackoverflow.com/questions/11388618/… 我想这就是你要找的。span>
-
这个问题描述了如何将通配符子域重定向到根域。我有兴趣将子域重定向到它们各自的根文件夹。不过还是谢谢。
-
尝试使用 .htaccess
-
请分享您当前虚拟主机的 Apache 配置。
标签: php linux apache dns subdomain