Hostwinds Tutorials
Search results for:
Table of Contents
Tags: htaccess
There are two main types of redirects, temporary and permanent. We will focus on another type of redirect called URL Masking in this guide and review how to accomplish URL Masking by Editing a .htaccess file.
Let's get started.
URL masking would be when you redirect to a new domain, but instead of the URL changing, it would stay the same. For example, if you have a domain mask redirect between yourdomain.com/example and yourdomain.com/example/mask. When domain.com redirects to yourdomain.com/example/mask, it will not switch the URL. It would continue to be yourdomain.com/example.
There are a couple of ways to make a redirect for your domain, like using code with HTML. We are going to be using your .htaccess file for this redirect mask. If you have not already created a .htaccess file, go check out our guide: Creating And Editing An .htaccess File. That guide will show you how to create and some ways to edit your .htaccess.
Now that you have your .htaccess file created, we can go ahead and use the following code to redirect your website with a URL mask.
#Making a URL Mask.
RewriteEngine On
RewriteRUle ^example/?$ /example2/mask
When someone opens up yourdomain.com, it will show the contents of another folder in example2 above. Replace examples above and example2 to display the desired content that you wish to have displayed.
#Redirect a domain to a specific URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^(.*) http://www.yourotherdomain.com/directory [P]
In the above example, replace yourdomain.com with your domain name and the domain you wish to send to in yourotherdomain.com.
When you put this code into your .htaccess, you will redirect and see the content for yourdomain.com/example/mask, but you will still see the URL for yourdomain.com/example.
Written by Hostwinds Team / August 1, 2019