Apache 重写等同于 AliasMatch

Apache Rewrite Equivalent to AliasMatch

提问人:Maciek 提问时间:8/30/2023 最后编辑:Maciek 更新时间:8/30/2023 访问量:8

问:

截至目前,我的代码如下所示:

 <VirtualHost *:443>
  ServerName article.example.com
  AliasMatch "^/(.*)" "/var/www/html/article.php"
 </VirtualHost>
 <VirtualHost *:443>
  ServerName company.example.com
  AliasMatch "^/(.*)" "/var/www/html/company.php"
 </VirtualHost>

这只是映射到文件。示例:将映射到 。与将映射到文件类似。article.example.comarticle.phparticle.example.com/testarticle.phpcompany.example.comcompany.php

我想包含一个通配符域扩展虚拟主机,并让它执行与上述相同的操作。这是我一直在测试的代码。这能实现吗?

 <VirtualHost *:443>
  ServerName example.com
  ServerAlias *.example.*
  AliasMatch "^article\.*.*/(.*)" "/var/www/html/article.php"
  AliasMatch "^company\.*.*/(.*)" "/var/www/html/company.php"
 </VirtualHost>

我需要使用重写引擎吗?(非工作示例)

 <VirtualHost *:443>
  ServerName example.com
  ServerAlias *.example.*
  AliasMatch "^article\.*.*/(.*)" "/var/www/html/article.php"
  AliasMatch "^company\.*.*/(.*)" "/var/www/html/company.php"
 </VirtualHost>

OR(使用重写引擎的非工作示例)

 <VirtualHost *:443>
  ServerName example.com
  ServerAlias *.example.*
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^article\.(.+)$ [NC][OR]
  RewriteCond %{HTTP_HOST} ^company\.(.+)$ [NC][OR]
  RewriteRule ???
 </VirtualHost>

当前版本(不起作用):

RewriteEngine On
RewriteCond %{HTTP_HOST} (article|company)\.example\. [NC]
RewriteRule (.*)\.example\. $1\.php
Apache 别名 virtualhost

评论


答: 暂无答案