0

I have a subdomain - cleveractions.clevercarbon.io. I wish to mask (not redirect) it so that it loads pages from the main domain thus:

cleveractions.clevercarbon.io => clevercarbon.io/cleveractions/
cleveractions.clevercarbon.io/page => clevercarbon.io/cleveractions/page

Within its .htaccess file I put this (based on the answer here):

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond "%{HTTP_HOST}"   "^cleveractions\.clevercarbon\.io" [NC]
RewriteCond "%{HTTP_HOST}"   "^$"
RewriteRule "^/?(.*)"        "https://clevercarbon.io/cleveractions/$1" [L]

The regex seems to be correct because it redirects just as I'd like - but it does not mask.

Ben
  • 1
  • 1

1 Answers1

1

The answer depends a bit on your actual situation, which you did not tell us...

In case both http hosts ("domains") get served by the same http server you can simply use an internal rewrite:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^cleveractions\.clevercarbon\.io$
RewriteCond %{REQUEST_URI} !^/cleveractions
RewriteRule ^ /cleveractions%{REQUEST_URI} [L]

If two separate http servers are involved then you'd need to proxy the requests, accepting a performance penalty because each and every request has to go through an additional proxy request:

Two alternatives here again which you'd have to implement in the http server serving "cleveractions.clevercarbon.io":

Either use the proxy module directly:

ProxyPass / https://clevercarbon.io/cleveractions/
ProxyPassReverse / https://clevercarbon.io/cleveractions/

Or use the proxy module embedded in the rewriting module:

RewriteEngine on
RewriteRule ^ https://clevercarbon.io/cleveractions%{REQUEST_URI} [P]

This proxy based approach requires the proxy module and the proxy_http module to be loaded into the http server serving "cleveractions.clevercarbon.io".

arkascha
  • 41,620
  • 7
  • 58
  • 90