Apache htaccess模拟多站点
我的web应用具有以下目录结构:Apache htaccess模拟多站点,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我的web应用具有以下目录结构: app_root/ includes/ config/ db.php [other config files] [other include files] services/ [various php files] templates/ [html files] [js/, css/, images/ directori
app_root/
includes/
config/
db.php
[other config files]
[other include files]
services/
[various php files]
templates/
[html files]
[js/, css/, images/ directories]
index.php
假设我在/var/www/projects/abc/
下有一个应用程序实例,这意味着应用程序的根是abc/
。可以使用http://host.com/projects/abc/
。现在,如果我将所有文件复制到/var/www/projects/xyz/
并更改配置文件,我将有一个可通过访问的第二个实例http://host.com/projects/xyz/
但是,随着应用程序得到bug修复和功能实现,所有实例的更改文件都应该更新。为了避免这种情况,我希望只有对等实例中的配置文件;像这样:
app_root/
includes/
config/
db.php
[other config files]
.htaccess
此方法将所有公共文件保留在abc
实例中,并且在每个对等方中仅具有特定于实例的文件
我尝试了以下规则,但我提出的请求得到了404:
RewriteEngine on
RewriteRule ^/xyz/(.+)$ /abc/$1
我在apache配置和中有AllowOverride All
。htaccess
规则被选中并应用于其他情况。我错过了什么
更新
我意识到在访问对等实例时需要传递一个参数。因此,我们的目标是重写:
到
显然
services/foo.php
是一个任意路径。在xyz/.htaccess中尝试此规则:
RewriteEngine On
RewriteRule (.*) ../abc/$1?instance=xyz [QSA,L]
尝试从中删除前导斜杠^/abc@starkeen仍在获取404。app\u root/
的完整路径是什么?这个.htaccess在哪里?@anubhava主实例的完整路径(包含所有文件,没有.htaccess
):/var/www/projects/abc/
。对等实例的完整路径(缺少公共文件且具有.htaccess
):/var/www/projects/xyz/
。.htaccess
自身的完整路径:/var/www/projects/xyz/.htaccess
@anubhava目标是拥有http://host.com/projects/xyz/services/foo.php
被重定向到http://host.com/projects/abc/services/foo.php?instance=xyz
。参数传递是我在问题发布后意识到的必要条件。这确实有效,谢谢。我将第二行更改为RewriteRule(.*)../abc/$1?instance=xyz[L]
,并传入了instance
参数。