Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite from one domain to another

Status
Not open for further replies.

TimFernihough

Programmer
Dec 16, 2008
3
I have two separate domains owned by the same company. There is a dynamic product list present on one of the sites, including pictures for each product. The second website draws from the same database remotely and displays the same product list. Since the product images are stored as files on the first domain, I have used mod_rewrite to link all image requests on domain 2, back to domain 1. For company political reasons, I cannot have a user visiting domain 2, know that the image is actually hosted on domain 1.

All normal rewriting (staying on the same domain) works just fine. However, the rewriting for images from Domain 2 to Domain 1 is experiencing some issues. Although it correctly resolves to the image, the address bar does not retain the rewritten URL. Rather, it simply changes to the URL that is being linked to like it is redirecting rather than rewriting. My .htaccess code is as below:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^catalogue_images/(.+)$   [URL unfurl="true"]http://www.domain2.com/$1[/URL] [L]

I tried this with and without the [L] and have had no luck. It always reverts to the original URL and does not retain the rewritten URL. Is this because you cannot rewrite to an external domain? If so, does anyone have a suggestion of a workaround to prevent the user from seeing the native URL? I realize this might be an inherent side effect of mod_rewrite due to potential malicious applications, but I have a unique scenario where both domains are owned by the same company.

Any help that anyone can suggest would be greatly appreciated.

Tim Fernihough
 
Instead of going through all that, why don't you just "Alias" the directory? That way you just put it in the the url as if it were in your domain's path.

 
Hmmm. Can you point me in the right direction of how I may go about this? I am not yet familiar with what "Aliasing" the directory entails. Thanks for your help and understanding RhythmAce.

Tim
 
It is very simple. First, open your httpd.conf. Let's say the common folder is called products. You would add the following line:

Code:
Alias /products/  "/path/to/products/"

What the Alias directive does is tell apache to pretend that the products directory is a sub-directory off the DocumentRoot. Since you put it in the main section of httpd.conf rather than a vhost container, it is said to be defined globally. Now you can use "any-domain.com/products. This is a great way to provide common files to all domains. For example, I provide Squirrelmail to all domains for their webmail. Rather than have a copy of squirrelmail in each domain's webspace, I use the fllowing:

Code:
Alias /webmail/ "/usr/share/squirrelmail/"

To access their webmail all they have to type is " Depending on your distro, you may be able to type any domain on your server followed by /manual and the apache manual should be displayed. Sorry for being so long winded but I thought you might want to know what the Alias directive does and how it works rather that just giving you a command to use.
 
That worked amazingly. Thanks Ace! It worked even easier because I host both domains.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top