redirection of group of folders

New to mod_rewrite? This is a good place to start.

redirection of group of folders

Postby rufuz » Thu May 21, 2009 10:28 am

Hi Richardk

I have to redirect some folders, I'm stuck with the rules....

Here the "human writing":

1) http://www.mysite.com/ (whatever directory and subdir here except for "templates" directory and its subdir) /images

has to be redirected to:

2) http://www.mysite.com/images

all image files seeked in 1) resides indeed in 2)

if the "templates" exception is not possible or too complex I can stand with:

1) http://mysite.com/directory/ (whatever directory here) /images

has to be redirected to:

2) http://mysite.com/images


Thank a lot, as always!

ricc.
rufuz
 
Posts: 16
Joined: Thu Aug 21, 2008 9:56 am

Postby richardk » Thu May 21, 2009 4:05 pm

Is your problem relative paths? The HMTL <base> element is a better solution. FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond $1 !^templates$
RewriteRule ^([^/]+)(/images/.*)$ $2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rufuz » Thu May 21, 2009 5:27 pm

richardk wrote:Is your problem relative paths? The HMTL <base> element is a better solution.


Yes and no. I mean the base is ok.

The issue is caused by a mootools tooltip that shows intro articles with images. It is the only js that can't get relative paths right....

look at the page I'm sending you in pm, at bottom, "related reportages", hover on a link to show the tooltip.

The intro article image is working elsewhere in the site except there.
It renders:

www.mysite.com/en/section/category/images/myimage.jpg

instead of

www.mystes.com/images (there's already a redirection to that directory: redirect 301 /en/images http://www.mysite.com/images)

By the moment it works for a simple redirect 301 I made for the whole section/category :

redirect 301 /en/section/category/images http://www.mysite.com/images

If you have any idea what's wrong with the mootools tooltip paths...
or don't worry I understand it could be off topic, I create as many redirects as the section/categories are (like 20... I hope this will not affect performance)... the code you posted seems ok, but I should have other images paths around the site and this mess up things...

thanks

ricc.
rufuz
 
Posts: 16
Joined: Thu Aug 21, 2008 9:56 am

Postby richardk » Fri May 22, 2009 8:10 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond $1 !^templates$
RewriteRule ^([^/]+)(/.+)?(/images/.*)$ $3 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 126 guests

cron