URL Masking using htaccess


This is the scenario -
I have a wordpress install and have the basic permalinks set up and works fine. But here is what I am trying to achieve

The current wordpress rewriting does it this way


Now I have another domain which I want to directly link to this.

meaning if someone types


the page displayed is

but the URL on top only shows thenewdomain.com and not the entire URL.

I used url redirection in htaccess and that works fine but not able to mask the URL
any ideas?

Could you… post the rewrite you tried for the newdomain.com rewrite?


like i said i m not able to mask the url as I do not know how to use masking in htaccess… the redirect htaccess that i am using is this

RewriteCond %{HTTP_HOST} ^newdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.newdomain.com$
RewriteRule ^/?$ "http\\:\\/\\/olddomain\\.com\\/category\\/this\\-is\\-my\\-title\\/\\ " [R=301,L]

I think your rewrite isn’t good; I mean, I see errors but I can’t say that if they were removed the problem would go away… but they don’t look correct.

RewriteCond %{HTTP_HOST} ^newdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.newdomain.com$
RewriteRule ^/?$ "http\:\/\/olddomain\.com\/category\/this\-is\-my\-title\/\ " [R=301,L]

First I think you can remove the OR and just look for both (though really, I’d think you’d always want one or the other: either always www or never www. The googles see www as one page and no-www as a completely different page).

RewriteCond %{HTTP_HOST} ^(www\\.)?newdomain.com$ [NC]

#so, IF the domain is newdomain.com...
#then do this redirect
RewriteRule .? http://olddomain.com/category/this-is-my-title/ [R=301,L]

Still, my Super N00b Senses (I’m an Apache n00b) are telling me this still isn’t quite the right way to go. But at least I could point out some of the errors.

I did look through DK’s page but I didn’t see an example quite like this.


Checked your rewrite htaccess. Basically both the one I had and the one which you provided have the same functionality - though your seems better. But the result is not as per my requirement

What this script is doing is simply redirecting to that page, while what I would like is URL Masking where in when someone visits the site say


then the page displayed is

but when some one sees the URL (on top) browser URL bar - he sees

http://addeddomain.com and not the complete URL.

Any idea how that could be done?

Thanks for the help.

Ok, I understand now; thanks for making it more clear.

Users type in newdomain.com, and only see newdomain.com in their address bar, but the page they see is at olddomain.com/category/this-in-my-title/

However this goes beyond my Apache knowledge; there may be a way to rewrite to another domain but all the examples from one domain to another I’ve run into so far were actual hard redirects (which show in the addressbar). Rewrites are transparent (people don’t see the true filename/path) but this may involve something different… I’ve heard of something called Domain Alias but that may have been specific to a particular hoster?

DK’s site says this:

(WordPress users will know that WP redirects EVERYTHING to index.php with the exclusion that it will not redirect existing directories or files.)

So there’s also WordPress things going on as well. I think I have to bow out here, and learn from the guru(s) who answer.


Nope, you’re WRONG that you got it wrong! Quite nice!

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\\.)?newdomain\\.com [NC]
RewriteRule .? http://olddomain.com/category/this-is-my-title/ [R=301,L]

All you missed was the No Case flag which is “required” when dealing with the case in-sensitive domain.




You canNOT change domain and hide the new URI. That is a SECURITY feature that Apache employs so your pages are not displayed as if they came from someone else’s website.

You CAN get around this if the NEWdomain is the master and the OLDdomain is located in a subdirectory of the NEWdomain. In that case, you would be inserting a directory in the path of the {REQUEST_URI} which can be hidden from the visitor’s browser.


WP has nothing to do with what Jaag is trying to get away with (see above).



Hi thanks for all the replies. currently i have managed through URL masking found in domain manager. that does the work as the newdomain.com is only visible in address bar even though pages change… But i had heard even through htaccess that could be done but will look in dept and see how it can be done…

thanks for the help.

All you missed was the No Case flag which is “required” when dealing with the case in-sensitive domain.

I had it in the Cond… do you mean it should also be in the rewriteRule part with R and L?

RewriteRule .? http://olddomain.com/category/this-is-my-title/ [[b]NC[/b],R=301,L] 


If so, makes sense, as there’s a {HOST} in the destination…

I read about something called “Domain Alias” on the page of some particular hoster… is this something outside of Apache then? Something hoster-specific?


Aw, bummer! You were completely correct - I missed that NC up there! Sorry about that!

Not sure about Domain Alias as that’s something in the VirtualHost (an alternate way to address a domain, i.e., with or without the www). I’m not sure that Jaag knows what this is about and certainly had the wrong idea about hiding the origin (domain) of a script.