Forum Moderators: phranque

Message Too Old, No Replies

Exclude images from rewrite - been struggling with this

         

mxfun

11:04 am on Nov 16, 2009 (gmt 0)

10+ Year Member



Hi,

I'm trying to redirect all traffic for our site when we do a maintence load. I've been struggeling with this for a week or so now.

If for example I access the site like this : [mysite.com...]
the maintence page shows perfectly. However if I access the site like :
[mysite.com...]
the page is displayed but all the css and images are not displayed due to the relative path issue.

Here's my rewrite:
Code:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/maintenance_files/.+\.(js¦css¦png¦jpg)$
RewriteCond %{REQUEST_URI} !^/.+\.(js¦css¦png¦jpg)$
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^ /maintenance.html [L]

DocumentRoot "/data/mysite/public"

any pointers would be most welcome.
thanks

jdMorgan

11:24 am on Nov 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change the object includes on the maintenance page to use server-relative or absolute links. That is, use <img src="/images/logo.gif"> or <img src="http://www.example.com/images.logo.gif"> instead of <img src="images/logo.gif">.

Do the same for the .css and .js includes.

Changing your mod_rewrite code really can't help, since it is the browser that resolves relative links, and in this case, it will resolve them based on the "directory-level" in the originally-requested URI, not the rewritten one.

Another option here would be to redirect the client to the maintenance page instead of using an internal rewrite.

And the best option would be to have an "A" and "B" copy of your site, do all updates and testing on "B", and then switch "A" with "B" only when ready to deploy the new version, avoiding this "maintenance" problem completely.

You can also simplify your first RewriteCond pattern to just "!^/maintenance_files/" since the excluded filetype pattern is redundant with your second rewritecond.

Jim

[edited by: jdMorgan at 4:02 pm (utc) on Nov. 16, 2009]

mxfun

3:22 pm on Nov 16, 2009 (gmt 0)

10+ Year Member



Hi Jim,

thanks you for taking time to answer with such a comprehensive answer.
I completly didn't think about changing the html. That did the trick perfectly thanks.

once again thanks :-)