1

Im trying to simplify the subdomain complexity perception to the user so I would like to mask the subdomain.

My goal is the following:

When the user tries to get here

blog.example.com/blog/whatever 

I would like to mask the subdomain to be

example.com/blog/whatever 

Same content served but with the subdomain hidden.

I have tried the following but with no success.

<IfModule mod_rewrite.c> RewriteCond %{HTTP_HOST} ^https://blog\.example.com\/blog [NC] RewriteRule ^(.*)$ http://example.com/blog/$1 [R=301,L] </IfModule> 

Update: Rewrite module is enabled

1
  • Are you seeing any errors on these rules? Or do you have other rules in your htaccess apart from these rules? Kindly do let us know on these questions. Commented Oct 25, 2021 at 15:01

1 Answer 1

1
RewriteCond %{HTTP_HOST} ^https://blog\.example.com\/blog [NC] RewriteRule ^(.*)$ http://example.com/blog/$1 [R=301,L] 

The HTTP Host header (ie. the value of the HTTP_HOST server variable) contains the hostname only, ie. blog.example.com. It does not contain the full absolute URL.

So, your rule should be like this instead:

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC] RewriteRule ^blog($|/) https://example.com%{REQUEST_URI} [R=301,L] 

This matches the URL-path /blog or /blog/<whatever> (but not /blog<something>) and redirects to the same URL-path at example.com (+ HTTPS). The REQUEST_URI server variable contains the root-relative URL-path, starting with a slash.

You were redirecting to HTTP, but I assume this must be HTTPS?

You should clear your browser cache before testing and test first with a 302 (temporary) redirect to avoid potential caching issues.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, you are right, should be https
@Imnl How did you get on with this?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.