How to redirect a top-level domain without impacting subfolders

So I got a ticket this morning (thank you Skidmore Domains!) regarding domain redirection and ending up teaching myself the fix thanks to my bff Google! Now I’m not sure if this solution is “best practice” since it involves tweaking the .htaccess file, but it worked and I’m proud of it nonetheless. :)

Support Scenario:

Can I redirect a top-level domain without impacting subdirectories of that domain?

For instance, let’s say I have a subdomain called bigpicture.labrumfield.com that I want to redirect to my main domain at labrumfield.com. Easy enough– all I would need to do is add the redirect in my cPanel account following this guide.

But let’s say that in addition to the above redirect, I also have an Omeka instance at bigpicture.labrumfield.com/omeka that I need to keep in tact. If I were to proceed with setting up a redirect in cPanel, all subdirectories, including my Omeka instance, would redirect to labrumfield.com as well.

To set up a redirect for the top-level domain only (or in this case my top level subdomain) we need to add a few conditions to the .htaccess file for the site that needs to be redirected, bigpicture.labrumfield.com.

If you’re not all too familiar with .htaccess files, you’ll need to know that this is a hidden file in your File Manager. To make sure hidden files are visible, click on Settings in the top right of your window and check Show Hidden Files:

(Psst, if you’re interested in learning more about .htaccess files in general,
I have an entire blog post dedicated to that here: Understanding .htaccess)

Next, navigate to the site directory that you’re redirecting, select .htaccess, and click edit:

In the next .htaccess window, add the following lines:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(www.)?bigpicture.labrumfield.com
RewriteRule (.*) https://labrumfield.com [R=301,L]

Here’s a screenshot of my .htaccess file:

And if you’ve got conflicting redirect rules like:

RewriteOptions inherit

that are currently listed, those need to be commented out or removed as well.

Press save changes. The proper redirects should start happening pretty immediately! (Also worth noting that you may need to clear your browser cache to see the changes.)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top