我正在尝试在<RewriteRule>
指令中创建<DirectoryMatch>
以执行以下重定向:
url/branch01/webservice/endpoint
=&gt; /branch01/webservice/public/index.php
url/branch02/webservice/endpoint
=&gt; /branch02/webservice/public/index.php
这是树结构:
/
├── branch01
| ├── webservice
| ├── public
| ├── index.php
├── branch01
| ├── webservice
| ├── public
| ├── index.php
...
我目前的设置如下:
AliasMatch ^/(.*)/webservice/(.*)$ /$1/webservice/public/$2
<DirectoryMatch ^/.*/webservice/public/>
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /webservice/public(.*)$ index.php [L,QSA]
</DirectoryMatch>
但这不起作用......
我可以访问index.php
文件,但重写似乎已经失败了。
以下是我从mod_rewrite获得的日志:
(3) [perdir ^/.*/webservice/public/] add path info postfix: branch01/webservice/public/user -> /branch01/webservice/public/user/login
(3) [perdir ^/.*/webservice/public/] applying pattern '/webservice/public(.*)$' to uri '/branch01/webservice/public/user/login'
(4) [perdir ^/.*/webservice/public/] RewriteCond: input='branch01/webservice/public/user' pattern='!-f' => matched
(2) [perdir ^/.*/webservice/public/] rewrite '/branch01/webservice/public/user/login' -> 'index.php'
(3) [perdir ^/.*/webservice/public/] add per-dir prefix: index.php -> ^/.*/webservice/public/index.php
我感觉它是日志的最后一部分失败,因为。*没有被真正的文件夹名称替换,但我不确定
如果有任何apache mod_rewrite专家,那将非常感谢帮助。 提前致谢
答案 0 :(得分:0)
这应该有效,即使没有AliasMatch
或DirectoryMatch
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule (^/[a-zA-Z0-9]+)/webservice/ $1/webservice/public/index.php [L,QSA]