Dynamically chaning image url, is this possible?

Using mod_rewrite to handle various content issues

Dynamically chaning image url, is this possible?

Postby obertor » Mon Apr 23, 2007 7:50 pm

Hi

is there a way to change

domain.com/:700/imagedir/imagefolder/image.jpg

to remove :700

domain.com/imagedir/imagefolder/image.jpg


On all pages under a directory

Using, modrewrite or a sql update string

thanks
obertor
 
Posts: 4
Joined: Mon Apr 23, 2007 7:48 pm

Postby richardk » Tue Apr 24, 2007 8:22 am

Is it a port or a directory? Mod_rewrite can't remove a port, but it can remove a directory.

If /imagedir is always in the URL
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(imagedir/.+)$ /:700/$1 [L]


If the whole URL changes
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/:700%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/:700%{REQUEST_URI} -d
RewriteRule ^(.+)$ /:700/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby obertor » Tue Apr 24, 2007 8:33 am

Actually, its a directory on another server that i own,

would that change anything?
obertor
 
Posts: 4
Joined: Mon Apr 23, 2007 7:48 pm

Postby richardk » Tue Apr 24, 2007 9:02 am

You have to put the .htaccess file in on the server with the /:700 directory on it.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby obertor » Tue Apr 24, 2007 7:53 pm

hmm ok thanks very much for the reply

So theres no way to do this only working with the first .htaccess file?
obertor
 
Posts: 4
Joined: Mon Apr 23, 2007 7:48 pm

Postby richardk » Wed Apr 25, 2007 5:25 am

You have to one of the mod_rewrites from my first post (or something similar) into a .htaccess file on the server that has the /:700 directory on it. Mod_rewrite cannot control URLs on a different server, it works on the incoming requests.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby obertor » Wed Apr 25, 2007 7:36 am

ok thanks, but just to be totally sure

On server 1 I want 1"domain.com/:700/imagedir/imagefolder/image.jpg" changed to show an image that is located at 2"domain.com/imagedir/imagefolder/image.jpg

The 1"domain.com/:700/imagedir/imagefolder/image.jpg" and 2"domain.com/700/imagedir/imagefolder/image.jpg" are on a different server

So there's no way to just change how this server interprets it and change where its loaded from? Or their is just no way to do it with modrewrite
obertor
 
Posts: 4
Joined: Mon Apr 23, 2007 7:48 pm

Postby richardk » Wed Apr 25, 2007 11:11 am

From what you've said, this is what you have and want:

On serverA you have a HTML page with an image in it that's located on serverB
Code: Select all
<img src="http://www.serverB.com/:700/imagedir/imagefolder/image.jpg" alt="An image.">

and you want to remove the /:700 from the path.

If that is the case, the mod_rewrite has to be on serverB and you have to actually edit the links to remove the /:700. This is because mod_rewrite works on the incoming request, so the image source has to be
Code: Select all
<img src="http://www.serverB.com/imagedir/imagefolder/image.jpg" alt="An image.">

and then when it's requested the mod_rewrite would run on serverB and add /:700 back into the path. There's no other way to remove /:700 from the path (without moving the files).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 14 guests

cron