Forum Moderators: phranque

Message Too Old, No Replies

Rewriting to Merge Out of Ideas

         

berrywoods

9:17 pm on Jan 1, 2010 (gmt 0)

10+ Year Member



Beg my pardon if this is something simple or even impossible, ive spent a total of 4 hours today looking for a solution.

I have a webshop and a forum, the webshop is one of these off the shelf hosted else where sites, easyier for me and my business, dont need to worry about too much during our first year. Forum is hosted on a server i set up with another host. At the moment domain name points to index file on my server which iframes users to my shop showing my domain name at the top, its only when a user goes into the forum's it can drill down.

Is there any way to rewrite so i can pritty much hide the fact the webshop is hosted else where, at the moment using iframes the URl is static, and the status bar gives away the orginal url, (which it self is a security issue)

so i can go to...

www.mysite.co.uk/catergories/dogs/ (which would in thoery be www.otherhost.co.uk/catergories/dogs

but when on forum the URL would be correct

forum is fine its just the shop

thanks in advance

berrywoods

9:33 pm on Jan 1, 2010 (gmt 0)

10+ Year Member



how typical that 10 minutes after i give up, i find the solusion.

if ANYONE happends to come across this post looking for the same solusion as me,

Options +FollowSymlinks
RewriteEngine On

RewriteEngine On
RewriteRule (.*) [websiteyouaremirroring.co.uk...] [P]

make sure you delete your index.html as i forgot...

jdMorgan

7:23 pm on Jan 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That should be

RewriteRule (.*) http://websiteyouaremirroring.co.u[b]k/$[/b]1 [P]

(only one slash) which invokes a reverse proxy through-put from your front-end 'site' server to the back-end 'shop' server.

Be aware, however, that all logs and 'stats' on the 'shop' server will show *all* requests as coming from the front-end server, and not from the original client. If this matters, then you will need to change the configuration on the front-end to send along the X-Forwarded-For header, and you will need to modify the 'shop' server to log that header instead of the Remote-Addr information in order to properly show the actual "user's" address. If you can't do that, then the best solution is to host the shop on your own server instead of using this 'partial' reverse-proxy set-up.

Jim

berrywoods

3:03 am on Jan 3, 2010 (gmt 0)

10+ Year Member



i see, the only problem that will cause is seeing the actual locations of my customers/users, the only reason i had to do it this way is there is no way for me to post the webshop, which is a pain, next year i plan to pay someone to remake my design onto magento, or simular, and i will host my self, but as it'll just be a trial this year, it was easyier this way.

jdMorgan

8:34 pm on Jan 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> ... the only problem that will cause is seeing the actual locations of my customers/users, the only reason i had to do it this way is there is no way for me to post the webshop

I don't understand that statement at all, but if the single-slash version doesn't work entirely correctly (as it indeed should), then there is something very wrong somewhere else in the server or system configuration.

Jim

berrywoods

7:35 pm on Jan 9, 2010 (gmt 0)

10+ Year Member



i did post one question but ive worked that one out but do have another, is it possible to have the rule that if the file is not found on the mirrored server it will look locally, ie www.mysite.co.uk/foo.gif
is not on the server im mirroring so look local instead? at the moment when im adding in my own images to the webshop (like animated gifs) the webshop software converts them to jpegs so i have to upload to my forum subdirector and link that way.

jdMorgan

8:44 pm on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could find (or infer) this fairly easily from the documentation, I think -- faster than waiting around for an answer here, especially on the weekend... :)

RewriteCond $1 !^robots\.txt$
RewriteRule ^(.*)$ http://mirror-example.com/$1 [P]

You might also want to consider excluding sitemap.xml, w3c/p3p.xml, labels.rdf, favicon.ico, and other "well-known-location-files" if you use them (with, for example, Google/Yahoo/MSN-Live-Bing) Webmaster Tools, ICRA, etc.)

Jim

jdMorgan

8:49 pm on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Answer to your edited question: No.
Once the request is proxied over to the back-end server, it can't "come back."

You might consider the reverse-logic approach: Don't proxy a request to the back-end if the requested object exists on your own server. That may require quite a bit of care and thought and list-making to be sure you've covered all of the if-and-or-buts in every case...

You may also find it useful to sort your files into different (sub)directories to simplify the logic and the rules needed to implement this correctly.

Jim

berrywoods

9:06 pm on Jan 9, 2010 (gmt 0)

10+ Year Member



i managed to exclude robots.txt using this...

Options +FollowSymlinks
RewriteEngine On

RewriteEngine On
RewriteBase /
RewriteRule ^(robots\.txt) - [L]
RewriteRule (.*) [mirrorurl.co.uk...] [P]

just some things i copyed and pasted from google.

Thanks for the 2x above code, the site map ect ive managed to also exclude as the one provided by the webshop host doesnt match my url vus google declines it.

thanks for your help so far, the amount i've picked up with regards to css javascript, php and this in the last few weeks is crazy... to think i quit my job for all this..

jdMorgan

4:20 pm on Jan 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd recommend:

RewriteEngine on
RewriteBase /
#
RewriteCond $1 !^robots\.txt$
RewriteRule ^(.*)$ http://mirror-example.com/$1 [P]

A bit of friendly advice: This is server configuration code. Cutting and pasting is ill-advised, unless you add the further step of taking the code you find and analyzing it using the mod_rewrite documentation and references such as the regular-expressions tutorial found in our Forum Charter. Only when you understand the intent of the code, the actual function of the code, and how these apply to your needs on your site is it 'safe' to use code you've found 'on some Web site.'

A quick survey of the Web shows that most code posted on-line is inefficient, broken, dangerous, or all of these... And that applies here at WebmasterWorld as well, unless someone has already replied to the thread and posted corrections. (That's because the source of the original code is often 'just some Web site' and the posted code was copied and pasted here without any analysis -- It's a vicious circle.)

Even then, there is no guarantee that code which is 100% technically-correct and efficiently-coded will work correctly (or at all) on your site -- In the abstract, it may do something quite correctly, but there's no guarantee that what it does is what you actually need to do on your site.

Bad or inappropriate code can take your server down instantly -- *if* you are lucky. If you're not lucky, one tiny little typo or subtle logic error may quietly destroy your user experience and/or search engine rankings over time.

Anyway, please don't use code that you've found 'out on the street' until you understand it completely and it has earned your trust...

Note that you don't need that RewriteBase directive to set the base back to "/" unless you've got another RewriteBase directive earlier in this file that has previously set the base to some other location. Unless you've changed it previously in this file, "/" is the default.

Jim