如何将子域名重写为 apache userdir

如何将子域名重写为 apache userdir

正如所述这个博客 我想内部重写

http://xy.user.phpfarm.lan -> http://user.phpfarm.lan/~xy/

模块 userdir 已启用。

以下 Apache2 vhost 配置文件存在一个错误:

在 /etc/apache2/sites-enabled /phpfarm中:

<Virtualhost *:80>
 ServerAdmin root@localhost
 ServerName em-sv-phpfarm.lan
 ServerAlias *.user.phpfarm.lan user.phpfarm.lan phpfarm.lan

 DocumentRoot /var/www/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog ${APACHE_LOG_DIR}/access.log combined

 RewriteLog "/tmp/rewrites"
 RewriteLogLevel 5
 # Uncomment the above two lines and watch /tmp for some debug info.

 RewriteEngine On

 # Make bob.user.phpfarm.em.lan be treated as user.phpfarm.lan/~bob
 RewriteCond %{HTTP_HOST} ([^.]+)\.user\.phpfarm\.lan$ [NC]
 # In the above line make sure you escape (preceed with a backslash) every period (.) in the address.
 RewriteCond %{REQUEST_URI} !^[^/]+/~.*$
 # exclude file handler
 RewriteCond %{REQUEST_URI} !^/php-fcgi/.*$
 RewriteRule ^/([^~]+) /~%1/$1 [PT,L]
</virtualhost>

所以我认为空的 REQUEST_URI 无法正确捕获。但我找不到错误。有人知道为什么吗?

答案1

尝试将最后一行替换为

重写规则 ^/([^~]*) /~%1/$1 [PT,L]

您坚持斜线后至少有一个字符,因此会忽略REQUEST_URI该情况。/

答案2

哦,就这样吧:你必须AllowOverride None 改变AllowOverride All

相关内容