简体   繁体   English

.HTaccess子目录重定向到其他服务器

[英].HTaccess Subdirectory Redirect to Different Server

I'm about to start running three different environments of our PHP application - Development, Staging and Production. 我将开始运行我们的PHP应用程序的三个不同环境-开发,暂存和生产。 Some of our customers will get access to Staging to help us test new features with real customers before it his production. 我们的一些客户将可以访问Staging,以帮助我们在实际客户生产产品之前对其进行测试。 Our application is running on AWS EC2 though an elastic load balancer using HTTPS only. 我们的应用程序通过仅使用HTTPS的弹性负载均衡器在AWS EC2上运行。 I need a way to allow users to go to https://mydomain.com/staging and be redirected to the staging environment (would still show https://mydomain.com/staging in the address bar, but they'd be getting content from a different set of servers). 我需要一种允许用户访问https://mydomain.com/staging并重定向到暂存环境的方法(仍然会在地址栏中显示https://mydomain.com/staging ,但他们会内容来自另一组服务器)。 There will be some code in Staging that will ensure their account has been approved for Staging access and will allow them in or redirect them to the main application. 登台中将包含一些代码,以确保其帐户已被批准用于登台访问,并将允许他们进入或重定向到主应用程序。

I can't seem to figure out how to write this in .htaccess. 我似乎无法弄清楚如何在.htaccess中编写此代码。 I've tried a number of things I've found online and haven't gotten it to work. 我已经尝试了很多在网上找到的东西,但是还没有开始工作。 I am beginning to think it may make more sense to have a real directory even in the production environment called 'staging' and have an index.php file inside that checks their account and redirects them based on the result. 我开始认为,即使在称为“ staging”的生产环境中拥有真实目录,并在其中具有index.php文件来检查其帐户并根据结果重定向它们,这可能更有意义。

However, I'd like to avoid having to purchase another SSL certificate for this, so instead of using a subdomain for staging, I'd like to use a virtual directory. 但是,我想避免为此购买另一个SSL证书,因此,我不想使用子域进行登台,而是想使用虚拟目录。 Does that make sense? 那有意义吗?

Thanks in advance. 提前致谢。

您需要在httpd配置文件中启用.htaccess的使用(可以通过在conf文件中找到具有AllowOverride None的行并将其更改为AllowOverride All来实现),然后将.htaccess放在html文件夹中的文件夹中通过以下行调用暂存

Redirect /staging http://whereverYourStagingEnvoIs

I would recommend using a subdomain instead of a subdirectory, staging.mydomain.com 我建议使用子域而不是子目录staging.mydomain.com

Then in your host records for mydomain.com you could point staging to whatever server you like. 然后,在mydomain.com的主机记录中,您可以将staging指向任何您喜欢的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM