Apache 重写为 admin.example.com 使用不同的 index.php

Apache rewrite to use a different index.php for admin.example.com

我的 Apache 生锈了,但我一直在努力尝试在共享托管服务器上为客户端创建一个管理员。

这是一个旧代码启动器站点,PHP 可以根据 URL 指定去哪里。

在 .htaccess 中,我正在尝试重写:

RewriteCond %{HTTP_HOST} ^staging\.admin\.example\.com$
RewriteRule ^$ "http\:\/\/staging\.example\.com\/admin\.index\.php"[L] 

目前,我只是想在没有 500 错误的情况下做到这一点。

虽然后来我想保护管理区,我打算尝试:

SetEnvIf Host admin.staging.example.com passreq
AuthType Basic
AuthName "Password Required"
AuthUserFile /home/user/.htpasswds/admin.staging.example.com/.htpasswd
Require valid-user
Order allow,deny
Allow from all
Deny from env=passreq
Satisfy any

我现在被告知托管服务提供商将在将我们转移到允许 SSH 登录的服务器的同时启用 mod_env(我坚持这一点)。

这是 Apache 2.4。谁能看出我哪里出错了,或者有其他建议吗?

谢谢! 克里斯

第二行不要使用双引号,试试下面的代码。

RewriteEngine On
RewriteBase /
# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ /index.php [L]
# for subdomain
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^$ /subdirectory/index.php [L]