Development Server - images and includes Aliases -will pay

Using a single web hosting account to host multiple sites

Development Server - images and includes Aliases -will pay

Postby mman » Tue Sep 30, 2008 7:37 am

Hello if anyone wants to tackle this I am willing to pay for your time. Plus I will post the solution here for the community.
PM if interested.

I currently use one server as a pre-production development server, where I host multiple domains under one document root.
On my production websites I typically us aliases for images and virtual includes.

Alias /images/ /var/www/example.com/images/
Alias /includes/ /var/www/example.com/includes/

My development server is setup like

<VirtualHost 192.168.0.59>
DocumentRoot /var/www/
DirectoryIndex index.html index.htm
</Virtualhost>

I have separate directories for domain
/var/www/example.com
/var/www/example2.com

I have issues when a page like
/var/www/example2.com/category/product/index.html makes reference to <img src="/images/prodpic.jpg">

Obviously the webserver looks at
/var/www/images/prodpic.jpg
and not
/var/www/example2.com/images/propic.jpg

Any ideas would be greatly appreciated.

Rob
mman
 
Posts: 5
Joined: Tue Sep 30, 2008 7:20 am

Postby richardk » Wed Oct 01, 2008 10:52 am

Use Name-based Virtual Hosts and your hosts file (or sub domains and DNS) instead.

The <VirtualHost>s
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
  ServerName example1.local
  ServerAlias www.example1.local
  DocumentRoot /var/www/example1.com
</VirtualHost>

<VirtualHost *:80>
  ServerName example2.local
  ServerAlias www.example2.local
  DocumentRoot /var/www/example2.com
</VirtualHost>


Added to your hosts file
Code: Select all
# dev_server_ip_address dev_domain [dev_domain [dev_domain [...]]]
127.0.0.1 example1.local www.example1.local
127.0.0.1 example2.local www.example2.local

(Note the use of .local so you can still access the .com domains.)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mman » Wed Oct 01, 2008 11:18 am

Richard thanks for the reply.
I think that would work great if I was just starting our or had few domains/developers to handle.

The issue is that I have 500+ domains under /var/www/ plus coders all over the place. I don't really want to have to set it in httpd.conf, dns and/or distribute hosts files.


If you knew the file path of the referring file??
/var/www/domain2.com/category/prod_name/index.html
Starting from the left match everything from /var/ww/ till you hit a .com|.net|.org|.tv
Change call for /images/pic.jpg
to
$1/images/pic.jpg

Or something like that.

Rob
mman
 
Posts: 5
Joined: Tue Sep 30, 2008 7:20 am

Postby richardk » Wed Oct 01, 2008 11:59 am

You can (sometimes, depending on browser and firewalls) get the referring URL
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_REFERER} ^http://(www\.)?example\.com/([^/]+\.(com|net|org|tv))(/.*)?$ [NC]
RewriteRule ^images(/.*)?$ /%2%{REQUEST_URI} [NC,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mman » Wed Oct 01, 2008 1:00 pm

Richard your example almost works
When the referer is
http://www.devel.com/example1.com/findlay/robtest.html
the %2 is coming out as "com"

Unfortunately my skills with regexps stink and I can't find the issue.

Thanks for the help

Rob
mman
 
Posts: 5
Joined: Tue Sep 30, 2008 7:20 am

Postby richardk » Wed Oct 01, 2008 2:32 pm

Did you remove "(www\.)?"?
Try %1 instead of %2. % is for variables from the last RewriteCond and the number is for the set of ().
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mman » Thu Oct 02, 2008 9:06 am

Richard I did remove the "(www\.)?"
My regexp experience is not so limited that I shouldn't have caught that one my self.

I have a working solution based on what you have provide along with some tinkering on my own. Anyone can please feel free to comment on how to improve it. I don't claim it is pretty or efficient, just that it works.

First two work when there is a refer available.

RewriteCond %{HTTP_REFERER} ^http://(noisy\.)?travelape\.com/([^/]+\.(com|net|org|tv))(/.*)?$ [NC]
RewriteRule ^.*images(/.*)?$ /%2/images$1 [NC,L]

RewriteCond %{HTTP_REFERER} ^http://(noisy\.)?travelape\.com/([^/]+\.(com|net|org|tv))(/.*)?$ [NC]
RewriteRule ^.*includes(/.*)?$ /%2/includes$1 [NC,L]

This works in instances when you don't have a referrer available. In my case when using Server Side Includes <!--include virtual="/includes/ads/banner.html" -->.

RewriteCond %{REQUEST_URI} ^.*includes/.*$
RewriteCond %{THE_REQUEST} ^GET./([^/]+\.(com|net|org|tv))(/.*)HTTP/1.1$
RewriteRule ^.*includes(/.*)?$ /%1/includes/$1 [L]

Many thanks to Richard and I hope this can help someone else out there.

Rob
mman
 
Posts: 5
Joined: Tue Sep 30, 2008 7:20 am

Postby richardk » Thu Oct 02, 2008 2:07 pm

This works in instances when you don't have a referrer available. In my case when using Server Side Includes <!--include virtual="/includes/ads/banner.html" -->.

RewriteCond %{REQUEST_URI} ^.*includes/.*$
RewriteCond %{THE_REQUEST} ^GET./([^/]+\.(com|net|org|tv))(/.*)HTTP/1.1$
RewriteRule ^.*includes(/.*)?$ /%1/includes/$1 [L]

How does it work? Is THE_REQUEST still set by the original request (of the SSI page)?

You do not need the first RewriteCond, it is doing the same thing as the RewriteRule.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mman » Thu Oct 02, 2008 2:15 pm

Yes that is what I am seeing.
If I access a page via
http://www.devserver.com/site1.com/cat/prod/index.html
and index.html has a SSI like <!--#include virtual="/includes/banner.html" -->

When apache is processing the SSI
THE_REQUEST is still
/var/www/site1.com/cat/prod/index.html

I only know that from trial and error during my last attempt to solve this problem a year or so ago.

Rob
mman
 
Posts: 5
Joined: Tue Sep 30, 2008 7:20 am

Postby richardk » Thu Oct 02, 2008 2:19 pm

Thanks, i shall remember that.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 13 guests

cron