Forum Moderators: phranque

Message Too Old, No Replies

rewriting a root?

         

noyearzero

1:35 pm on Sep 24, 2008 (gmt 0)

10+ Year Member



in the browser world if you make an image "/images/picture.jpg" it looks in the root for the folder images... we have a test server that we use to test all our pages on so lets say we have a site

www.newsite.com

and our coresponding test site

www.ourtestserver.com/sites/newsite.com

on the test server that same image example would resolve to "www.ourtestserver.com/images/picture.jpg" and not "www.ourtestserver.com/sites/newsite.com/images/picture.jpg"

any ideas of the best way to accomplish this. preferably an .htaccess file we could plop in each sites directory?

Thanks

g1smd

2:15 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, a rewrite or redirect would do it, but that code will probably need to be located at www.ourtestserver.com/.htaccess or at www.ourtestserver.com/images/.htaccess to work.

I assume that you stop all search engines from accessing the test site. That would be a quite vital step to take. I mostly use password protection rather than rely on robots tags or files.

Somehow the .htaccess file would need to know which "site" to rewrite or redirect back to for images only. You could use the referrer data for that I suspect. You would only need one file to work for all of your test sites.

I am not sure whether it is best coded as a redirect or as a rewrite. If search engines aren't involved then it may not matter.

.

This is guesswork, and might get you started:

RewriteCond %{HTTP_REFERER} http://www\.ourtestserver\.com/sites/([^\?])\?
RewriteRule ^images/([^.]+\.(jpeg?¦png¦gif)) /sites/%1/images/$1 [L]

I assume there is no site in the root of the test domain. If there is, then you will need to add exclusions for that, otherwise images for that site may well fail to display.

.

I tackle this in the site scripting. There's a variable in the first PHP include that defines "path to images", among other things.

Sometimes I automate it in PHP, by testing the domain name a nd setting the path depending on whether the test server or live server is detected.

[edited by: g1smd at 2:43 pm (utc) on Sep. 24, 2008]

jdMorgan

2:35 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The proper way to do this is to configure your test server so that it is identical to the real server, by defining a new virtual host in httpd.conf for testsite.com, and using the 'real' DocumentRoot directory.

Referrer-based rewrites are problematic, in that many plug-ins and media players will not send a referrer header, and this can lead to unexpected failures of referrer-based logic (and rewrites). If you choose to use the mod_rewrite-based approach, then I'd suggest using the HTTP_HOST variable as the basis for rewriting, instead of HTTP_REFERER.

Jim

noyearzero

3:38 pm on Sep 24, 2008 (gmt 0)

10+ Year Member



Thanks guys.

the more i thought about it, the more i figured a virtual host was the right answer. but i'm not quite sure how to configure that right.

to complicate things our test server url is like "admin.realserver.com" admin being a subdomain pointed to the test server's IP. so in the end i'd end up having a url like:

[newsite.com.admin.realserver.com...] ?

doesn't that mean i'd have to set up A records on the realserver?

or i was also thinking set up [newsite.com.255.255.255.255...] but there are two websites set up at this IP and the default destination is not the one i want to be using.