Reputation: 125
I currently have a main website, in Angular, and a few landing pages as subdomains, in pure HTML/JS.
I was requested that instead of lp.website.com
, the urls should now be website.com/lp
.
Considering that the folders for all of the pages and the angular app are on the same server under Apache, how could I redirect the user to the appropriate content, but keeping the website.com/lp
URL?
Upvotes: 0
Views: 178
Reputation: 579
If you create a rewrite rule in your .htaccess file you can create an alias. This way you can keep the current structure completely intact, until you can phase out the subdomain landing pages.
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/
The RewriteRule does the following:
The user requests https://example.com/lp/
, but after rewriting the server 'thinks' the user requested https://lp.example.com/
Here is an example the other way around.
# 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/
The server receives a request for https://lp.example.com
. The rewrite condition ensures the rewrite only happens for lp.example.com. The RewriteRule does an internal redirect to http://example.com/lp/
More information https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule
Upvotes: 1