.htaccess URL Masking Examples

If you would like to access a specific URL for your domain but do not display it in the browser's address bar, here is how you can accomplish it using .htaccess URL Masking.

Note: URL Masking will produce doublicated content and can cause ranking drops in one, or both of the sites.
From an SEO standpoint, your best option is to create 301 redirects instead. You can use our simple .htaccess 301 Redirect Generator.


Example 1

#Show content from a different path on the same domain
#This way each time someone accesses yourdomain.com/path the actual content that will be displayed will be for yourdomain.com/different/path while the URL will remain unchanged.
RewriteEngine On
RewriteRule ^path/?$ /different/path/

Example 2

#Redirect and keep everything after the URL
#Visit yourdomainA.com/page and it will show the content from yourdomainB.com/page
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomainA.com
RewriteRule ^(.*) http://www.yourdomainB.com/$1 [P]

Example 3

#Redirect a domain to a specific url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://www.DomainB.com/directory [P]

Example 4

# Redirect all IP address (replace ### with the actual IP address) to same http://www.yourdomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^###\.###\.###\.###
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

  • 75 Users Found This Useful
Was this answer helpful?

Related Articles

Do you support mod_rewrite for apache?

Yes, mod_rewrite is enabled on your server. For more information on what mod_rewrite is and how...

How to execute php code as .htm or .html files

In your .htaccess file insert this line of code. addhandler application/x-httpd-php .htm .html

Disabling Magic Quotes GPC

How to turn off magic quotes gpc (required by Joomla 3 and some other scripts).1. Create a...

Block Bad Bots and Spiders using .htaccess

Below is a useful code block for blocking a lot of the known bad bots and site rippers currently...

.htaccess RewriteRule Examples

Here are some useful mod_rewrite RewriteRule redirect examples that you can use in your .htaccess...