将用户重定向到 Angular 之外的内容,但作为应用程序的子路径

Redirect users to content outside Angular but as a subpath of the application

我目前有一个主网站,在 Angular 中,还有一些作为子域的登录页面,在 HTML/JS 中。
有人要求我现在的网址应该是 website.com/lp.

而不是 lp.website.com

考虑到所有页面的文件夹和 angular 应用程序都在 Apache 下的同一台服务器上,我如何才能将用户重定向到适当的内容,但保留 website.com/lp URL?

如果您在 .htaccess 文件中创建重写规则,则可以创建别名。这样您就可以保持当前结构完整无缺,直到您可以逐步淘汰子域登录页面。

RewriteEngine on

#Make sure we only rewrite for domains example.com and www.example.com
RewriteCond ${HTTP_HOST} ^(www\.)?example.com$

# If the request URI is either /lp or /lp/ do an internal redirect
# (The leading slash of the request URI is stripped before matching)
RewriteRule ^lp/?$ https://lp.example.com/

RewriteRule 执行以下操作:

用户请求 https://example.com/lp/,但重写服务器后 'thinks' 用户请求 https://lp.example.com/

这是一个反过来的例子。

# Make sure we only rewrite for the lp.example.com domain
RewriteCond ${HTTP_HOST} ^lp.example.com$
# Rewrite all root requests to https://example.com/lp/
RewriteRule ^/?$ https://example.com/lp/

服务器收到 https://lp.example.com 的请求。重写条件确保重写只发生在 lp.example.com。 RewriteRule 将内部重定向到 http://example.com/lp/

更多信息https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule