Apache重写URL以被AliasMatch捕获

我需要mod_rewrite重新映射传入的URL,以便它被AliasMatch捕获。

 RewriteCond %{REQUEST_URI} ^/app/(.*)$ RewriteRule ^/app/(.*) ^/dev-dave/app/$1 RewriteCond %{REQUEST_URI} ^/static/(.*)$ RewriteRule ^/static/(.*) ^/dev-dave/static/$1 AliasMatch ^/(.*)/static/(.*)$ /var/www/html/cosmos/$1/dist/static/$2 AliasMatch ^/(.*)/app/(.*)$ /var/www/html/cosmos/$1/dist/index.html <Directory /var/www/html/cosmos> AllowOverride None Require all granted <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d </IfModule> </Directory> 

这可能吗? 我无法得到这个工作。

在主服务器configuration中,您应该使用RewriteRule指令上的PTpassthrough )标志,您希望被AliasMatch 。 ( PT标志隐含在目录上下文中,因此,在<Directory>容器中的文件后面出现的指令中不需要该标志。)

PT标志的Apache文档 :

RewriteRule中的目标(或replacestring)默认为文件path。 使用[PT]标志会将其视为一个URI。 也就是说,使用[PT]标志会导致RewriteRule的结果通过URL映射传回, 因此基于位置的映射(例如,Alias,Redirect或ScriptAlias)可能有机会生效

例如,如果你有一个/图标的别名,并有一个RewriteRule指向那里,你应该使用[PT]标志来确保Alias被评估


  RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

另外:您的前端控制器 ,稍后定义,缺lessRewriteRule指令? 所以这在目前的状态下不会做任何事情。 但是,它也容易出错…如果稍后在<Directory>容器中添加了RewriteRule指令,则上述条件将会(意外)应用。