MasterGberry
MasterGberry

Reputation: 2860

How to rewrite URL on back-end only

I am trying to take this rewrite rule I have and only make it re-write (handle) on the back-end, i don't want the user's URL to actually change. My objective is to take i.website.com and put this on a CDN, but leave the rest of the website not on a CDN. Right now i.website.com forwards to www.website.com/images/ but I want to just have it handle on the back-end and make it so when the user visits i.website.com/asdasd.jpg it doesn't forward the URL so the CDN works?

I think i got that right...anyways here is my current rewrite, maybe there is a better approach to do this, I am open to suggestions and willing to answer any further questions.

Thanks

RewriteCond %{HTTP_HOST} ^i\.website\.com [NC]
RewriteRule ^(.+)$ http://www.website.com/images/$1 [L,R=301]

Upvotes: 0

Views: 109

Answers (1)

David Ravetti
David Ravetti

Reputation: 2040

Based on your comment, I think this scenario may be what you're looking for:

On your local server, you host www.website.com, including www.website.com/images exactly as you're doing now.

On the CDN, you host i.website.com. You can set up the CDN to pull content for i.website.com from www.website.com/images just like your rewrite rule does now (the rewrite rule would be unnecessary on your server now).

The only question is, when you say that "The application is designed to take www.website.com/images/ and feed it to the right script, but not i.website.com", do you mean that the application/script pull content from www.website.com/images for processing or do you mean that the application/script write out webpages that link to images on www.website.com/images, but not on i.website.com?

If it's just a matter of the application/script needing to pull content from the www.website.com/images/, that's fine as long as the site's pages can be written with image links to i.website.com. In that case, the final piece is that you essentially reverse your rewrite rule to direct all outside traffic from www.website.com/images/ to i.website.com in order to handle older links, while keeping internal traffic (your application/script) pulling from www.website.com/images/.

Upvotes: 1

Related Questions