How can I rewrite the image paths on my web server?
May 21, 2009 5:09 PM   Subscribe

How can I rewrite the image paths on my web server?

I recently moved a site into a CMS and different web server. The images are in directories like this:
/daily/2009/05/

The web pages sometimes link to images like this:
[img src="/daily/2009/05/"]
And sometimes they link to images like this (without a leading slash):
[img src="daily/2009/05/"]

That worked fine on the old server, but the paths are different in the CMS on the new server. Can I use .htaccess or something to rewrite the paths?
posted by kirkaracha to Computers & Internet (4 answers total)
 
Which CMS are we talking about? More to the point, what kind of database? You probably want to do a search-and-replace in some of the tables in the database to rectify the image links.
posted by bricoleur at 6:48 PM on May 21, 2009


"Rewrite" usually has a fairly specific meaning referring to an internal operation within a running web server that causes each HTTP request to return a file at a different location than the request's URL would normally correspond to. Is that what you're talking about doing?

And more generally, whatever you mean in particular by "rewrite", are you asking about this to remedy a problem involving broken image links or for a different reason?
posted by XMLicious at 7:31 PM on May 21, 2009


Response by poster: ExpressionEngine, MySQL, broken image links.
posted by kirkaracha at 7:33 PM on May 21, 2009


Assuming /daily/ is the correct link, and doesn't appear in other URLs then you could probably do something like (not tested):

RewriteRule ^.+/daily/(.+)$ /daily/$1

Should match anything where there are path parts before the /daily/ (so where the image URL has been linked as a relative link) and rewrite to an absolute root-based URL.
posted by sycophant at 1:47 AM on May 22, 2009


« Older Buying original art in china   |   Can I transfer voice-mail messages to my PC ? Newer »
This thread is closed to new comments.