apache htaccess将应用程序根目录重定向到不存在的子目录

时间:2018-07-11 18:35:41

标签: php apache .htaccess localhost lamp

我有一个灯栈应用程序,已部署到example.com/directory/进行生产。生产环境会将流量重定向到/ directory /,然后直接从该位置提供应用。

在本地开发时,我想通过提供位于我的应用程序根文件夹中的文件来复制它

localhost:33309/directory/

代替

localhost:33309

在我的应用程序根.htaccess文件中,我尝试了很多操作。下面的示例可以很好地重定向流量,但是如何使该路径提供不在/ directory /中的内容?

RewriteEngine on
# route to directory from app root
RedirectMatch ^/$ /directory/

我不想在本地创建/ directory文件夹,我只想让我的本地主机看起来像是在不存在的目录路径下为应用程序提供服务。

想知道我是否需要对VirtualHosts做一些事情,或者是否可以进行配置?

2 个答案:

答案 0 :(得分:1)

尝试以下规则,

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/directory/(.*)$
RewriteRule ^ /%1 [L]

答案 1 :(得分:0)

我认为您想要别名: 别名“ / directory /”“ /”