首页 > 解决方案 > 将我的根 url 映射到子目录

问题描述

我的问题很简单:如何将我的 url root 别名为我的子目录之一?

假设我网站的网址是

https://example.com

我的文档根目录是

/home/user/web

但是,我想通过上面的 URL 来访问

/home/user/web/app

我似乎无法使用

Alias / /app/

我尝试按照这个类似的答案 [here] ( .htaccess: Redirect root url to subdirectory, but retain root url ) 添加

RedirectMatch 301 ^/app/.*$ https://example.com/

我最终会得到:

This page isn’t working
example.com redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

我该怎么办?

标签: htmlapache.htaccessalias

解决方案


您可以访问 httpd.conf 吗?然后你可以简单地改变 DocumentRoot

DocumentRoot "/home/user/web/app"

或者,如果您在那台机器上有更多域,请使用虚拟主机。或重写:

RewriteEngine On
RewriteRule ^(.*)$ %{HTTP_HOST}/app/$1 [R=301,L]

或重定向匹配:

RedirectMatch 301 ^/$ https://example.com/apps

另一种选择是文件系统上的符号链接。

首先尝试不使用 https - 查看普通的 http 工作。


推荐阅读