哎呀!一直在捣乱,但我似乎无法让它正常工作。
我有像
这样的目录结构/var/www/site
/var/www/site/ui
/var/www/site/api
/var/www/site/apidocs
我将DocumentRoot设置为/ var / www / site 并尝试了大约100种不同的东西,包括Alias(他们曾经在他们自己的dirs中)和Rewrites当然,但我尝试的任何东西似乎都运作良好。 API正在使用Phalcon,UI和API都有自己的git repo,因此我可以将它们组合起来,它们需要保持独立。
这就是我所拥有的不起作用......
<VirtualHost *:80>
ServerName dev.tld.com
ServerAlias dev
DocumentRoot /var/www/site
AddDefaultCharset UTF-8
RewriteRule ^/.* /var/www/site/ui/index.html
<Directory /var/www/site/ui/>
Options All
AllowOverride All
Allow from all
</Directory>
<DirectoryMatch .*\.git/.*>
Deny From All
</DirectoryMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerSignature Off
LogLevel alert rewrite:trace6
</VirtualHost>
<VirtualHost *:80>
ServerName dev.tld.com
ServerAlias dev
ServerPath /api/
RewriteEngine on
RewriteRule ^(/api/.*) /var/www/site/api$1
<Directory /var/www/site/api/>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ((?s).*) public/$1 [L]
Options All
AllowOverride All
Allow from all
</Directory>
<Directory "/var/www/site/api/public">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</Directory>
<DirectoryMatch .*\.git/.*>
Deny From All
</DirectoryMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerSignature Off
LogLevel alert rewrite:trace6
</VirtualHost>
<VirtualHost *:80>
ServerName dev.tld.com
ServerAlias dev
ServerPath /apidoc
DocumentRoot /var/www/site/apidoc
<Directory /var/www/site/apidoc/>
Options All
AllowOverride All
Allow from all
</Directory>
<DirectoryMatch .*\.git/.*>
Deny From All
</DirectoryMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerSignature Off
LogLevel alert rewrite:trace6
</VirtualHost>
根据Phalcon文档,我还需要为api做一些重定向,你在上面看到/ api目录
我甚至没有试过让apidoc工作了......
编辑: 通过大大简化它,我已经设法得到了更多。主UI加载,但API返回500错误。
这就是我所拥有的:
<VirtualHost *:80>
ServerName lz4dev.tld.com
ServerAlias dev
DocumentRoot /var/www/site
AddDefaultCharset UTF-8
RewriteEngine On
RedirectMatch ^/$ /ui/
Alias /api /var/www/site/api
Alias /apidoc /var/www/site/apidoc
<Directory /var/www/site/ui/>
Options All
AllowOverride All
Allow from all
</Directory>
<Directory /var/www/site/api/>
Options All
AllowOverride All
Allow from all
</Directory>
<Directory /var/www/site/apidocs/>
Options All
AllowOverride All
Allow from all
</Directory>
<DirectoryMatch .*\.git/.*>
Deny From All
</DirectoryMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerSignature Off
LogLevel alert rewrite:trace6
</VirtualHost>
然后在api / .htaccess中,我有:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ((?s).*) public/$1 [L]
</IfModule>
在api / public / .htaccess中,我有:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
以下是错误日志的最后几行:
[Thu Sep 17 13:42:56.808052 2015] [rewrite:trace3] [pid 472] mod_rewrite.c(468): [client 10.2.180.248:53810] 10.2.180.248 - - [dev.tld.com/sid#7fc91bf345c8][rid#7fc91bef7390/initial/redir#2] [perdir /var/www/site/api/public/] strip per-dir prefix: /var/www/site/api/public/index.php -> index.php, referer: http://dev.tld.com/ui/
[Thu Sep 17 13:42:56.808063 2015] [rewrite:trace3] [pid 472] mod_rewrite.c(468): [client 10.2.180.248:53810] 10.2.180.248 - - [dev.tld.com/sid#7fc91bf345c8][rid#7fc91bef7390/initial/redir#2] [perdir /var/www/site/api/public/] applying pattern '^((?s).*)$' to uri 'index.php', referer: http://dev.tld.com/ui/
[Thu Sep 17 13:42:56.808075 2015] [rewrite:trace4] [pid 472] mod_rewrite.c(468): [client 10.2.180.248:53810] 10.2.180.248 - - [dev.tld.com/sid#7fc91bf345c8][rid#7fc91bef7390/initial/redir#2] [perdir /var/www/site/api/public/] RewriteCond: input='/var/www/site/api/public/index.php' pattern='!-d' => matched, referer: http://dev.tld.com/ui/
[Thu Sep 17 13:42:56.808094 2015] [rewrite:trace4] [pid 472] mod_rewrite.c(468): [client 10.2.180.248:53810] 10.2.180.248 - - [dev.tld.com/sid#7fc91bf345c8][rid#7fc91bef7390/initial/redir#2] [perdir /var/www/site/api/public/] RewriteCond: input='/var/www/site/api/public/index.php' pattern='!-f' => not-matched, referer: http://dev.tld.com/ui/
[Thu Sep 17 13:42:56.808102 2015] [rewrite:trace1] [pid 472] mod_rewrite.c(468): [client 10.2.180.248:53810] 10.2.180.248 - - [dev.tld.com/sid#7fc91bf345c8][rid#7fc91bef7390/initial/redir#2] [perdir /var/www/site/api/public/] pass through /var/www/site/api/public/index.php, referer: http://dev.tld.com/ui/
答案 0 :(得分:0)
成功!
这是我最终的结果:
<VirtualHost *:80>
ServerName lz4dev.tld.com
ServerAlias dev
DocumentRoot /var/www/site
AddDefaultCharset UTF-8
RewriteEngine On
RedirectMatch ^/$ /ui/
Alias /api /var/www/site/api
Alias /apidoc /var/www/site/apidoc
<Directory /var/www/site/ui/>
Options All
AllowOverride All
Allow from all
</Directory>
<Directory /var/www/site/api/>
Options All
AllowOverride All
Allow from all
</Directory>
<Directory /var/www/site/apidocs/>
Options All
AllowOverride All
Allow from all
</Directory>
<DirectoryMatch .*\.git/.*>
Deny From All
</DirectoryMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerSignature Off
LogLevel alert rewrite:trace6
</VirtualHost>
在api / public / .htaccess中,我必须添加/ api /到规则中,如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/api/$1 [QSA,L]
</IfModule>